Title in TMultigraph

Hi,

I’m unable to draw a title above a TMultiGraph. How are they added?

First I create a TMultiGraph, then I add 4 TGraph’s to it, then I use TMultiGraph::SetTitle(“title”), but none appears above my graph. When I use the GUI canvas and use the menu < SetTitle, “title” is already filled in…

Thanks,
Japdhaes

[url]Order of calling methods with TMultiGraph

Is this a bug then?

Example:


{
   TCanvas *c2 = new TCanvas("c2","c2",600,400);

   TGraph *g[3];
   Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
   Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
   TMultiGraph *mg = new TMultiGraph();
   for (int i=0; i<3; i++) {
      g[i] = new TGraph(10, x, y);
      g[i]->SetMarkerStyle(20);
      g[i]->SetMarkerColor(i+2);
      for (int j=0; j<10; j++) y[j] = y[j]-1;
      mg->Add(g[i]);
   }
   mg->Draw("APL");
   mg->GetXaxis()->SetTitle("E_{#gamma} (GeV)");
   mg->GetYaxis()->SetTitle("Coefficients");
   mg->GetHistogram()->SetTitle("Global title");
}

Your example looks like a workaround to me. Does this mean the TGraphPainter ignores the TNamed::fName for TMultiGraph?

No it is the right way. TMultiGraph is on a list of graph. When you draw a TMultiGraph, the first thing drawn is an empty histogram to draw the frame. The global title is hold by this histogram. Them the graphs are drawn sequentially in that frame.

Should that histogram then be assigned the title from the TMultiGraph constructor?

It is build at drawing time only because the limits can change if a new graph is added for instance.

But your point makes sense … I will check

In fact you should do:

   TCanvas *c2 = new TCanvas("c2","c2",600,400);

   TGraph *g[3];
   Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
   Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
   TMultiGraph *mg = new TMultiGraph();
   mg->SetTitle("Global title; X Axis; Y Axis");
   for (int i=0; i<3; i++) {
      g[i] = new TGraph(10, x, y);
      g[i]->SetMarkerStyle(20);
      g[i]->SetMarkerColor(i+2);
      for (int j=0; j<10; j++) y[j] = y[j]-1;
      mg->Add(g[i]);
   }
   mg->Draw("APL");