TMultiGraph and its GetHistogram

Hi,
I am always confused about the method GetHistogram of TMultiGraph. See the code below please. In the example code, I try to use 2 ways to draw a TMultiGraph. Due to my understanding, either a common draw option or several same draw options specified individually should give the same graph. However, they don’t. And also, GetHistogram() is null when using the 2nd approach. Please use the bool variable “switch” to see the difference.

Am I misunderstanding somethings?

Cheers,
Zhiyi.

{
  float x1[] = {1,2,3}; float y1[] = {4,7,6};
  float x2[] = {3,5,6}; float y2[] = {0,9,4};
  
  TGraph *gr1 = new TGraph(3,x1,y1);
  TGraph *gr2 = new TGraph(3,x2,y2);

  bool successful = false;
  TMultiGraph *mg1 = new TMultiGraph();

  if ( successful ) {
    
    mg1->Add(gr1);
    mg1->Add(gr2);
    mg1->Draw("APL");

  }
  else {
   //not working lines:
    mg1->Add(gr1, "APL");
    mg1->Add(gr2, "APL");
    mg1->Draw();
  }
   
  cout << "Pointer of Histogram: "  << mg1->GetHistogram() << endl;
   
}

You should not put the option A when you add a TGraph in a TMultigraph. That does not make sense.

Sure, but GetHistogram() still returns NULL. For this case, how can I change histogram axis properties if it is NULL?

It works for me, it is not NULL:

{
  float x1[] = {1,2,3}; float y1[] = {4,7,6};
  float x2[] = {3,5,6}; float y2[] = {0,9,4};

  TGraph *gr1 = new TGraph(3,x1,y1);
  TGraph *gr2 = new TGraph(3,x2,y2);

  TMultiGraph *mg1 = new TMultiGraph();

  mg1->Add(gr1);
  mg1->Add(gr2);
  mg1->Draw("APL");
  cout << "Pointer of Histogram: "  << mg1->GetHistogram() << endl;
}

gives:

root [0] .x mg.C
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Pointer of Histogram: 0x9dae008
root [1] .q

Nope, what I mean is the 2nd way:

    mg1->Add(gr1, "APL");
    mg1->Add(gr2, "PL");
    mg1->Add(gr1, "PL");
    mg1->Draw();
    cout << "Pointer of Histogram: "  << mg1->GetHistogram() << endl;

That’s what I mean you should not put the “A” option in the Add method

Okay, I see now. Since I need to specify each draw option by Add, the working lines are for me, for example:

    mg1->Add(gr1, "p");
    mg1->Add(gr2, "3");
    mg1->Draw("A");