TMultiGraph->GetXaxis()->SetTitle (version 4.01)

I’ve run into this again recently and am a bit frustrated with the behavior. How can someone write a routine that returns a TMultiGraph to the user without plotting it? Why does TGraph allow the axis titles to be set without a call to gPad->Update()? (I’m using ROOT 6.11.02 here.)

This problem has come up a number of times in the past and I think that it is disconcerting that the behavior is different than TGraph. At some point in the past this same issue also came up with TGraph2D and it was suggested that this behavior is a bug and should be corrected:

A few of the previous complaints about TMultiGraph:

An example:

TMultiGraph* MakeGraph(bool verbose = true) {
   const int numPoints = 3;
   float x[numPoints] = {5, 8, 9};
   float y1s[numPoints] = {10, 13, 8};
   float y2s[numPoints] = {11, 12, 7};
   TGraph *g1 = new TGraph(3, x, y1s);
   TGraph *g2 = new TGraph(3, x, y2s);
   g2->SetLineColor(kRed);
   g2->SetMarkerColor(kRed);

   TMultiGraph *mg = new TMultiGraph();
   mg->Add(g1);
   mg->Add(g2);

   g1->GetXaxis()->SetTitle("X-axis");
   g2->GetYaxis()->SetTitle("Y-axis");

   //Guess we have to check if the Axis (Histogram) is defined.
   if (mg->GetXaxis() && mg->GetYaxis()) {
      mg->GetXaxis()->SetTitle("X-axis");
      mg->GetYaxis()->SetTitle("Y-axis");
   }

   if (verbose) {
      printf("TGraph: %p TMultiGraph %p\n", g1->GetHistogram(), mg->GetHistogram());
   }

   return mg;
}

void multigraph_example() {

   TMultiGraph *mg = MakeGraph();

   //Ahhh it crashes! Would not have expected to have to check for nulls from every method.
   std::cout << "X-axis label: " << mg->GetXaxis()->GetTitle() << "\n";
}

(11 years later! :cry:)