TMultiGraph

Hi all,

I know this has been posted before, but is there a consistent way to draw a TMultiGraph and set the axes limits and titles?

Do you have to Update the canvas after drawing? Do you have to call c->Modified() after setting the limits? The tutorial does not help and previous posts on the ROOT forums are inconsistent. Which out of the confusing mess below will actually work?

Cheers

Alex

    TMultiGraph *mg = new TMultiGraph;
    mg->SetTitle(title);
    mg->Add(g1);
    mg->Add(g2);
    double xmax1,xmin1,ymax1,ymin1;
    double ymax2,ymin2,xmax2,xmin2;
    g1->ComputeRange(xmin1,ymin1,xmax1,ymax1);
    g2->ComputeRange(xmin2,ymin2,xmax2,ymax2);
    mg->GetYaxis()->SetRangeUser(0,std::max(ymax1,ymax2));
    mg->SetMaximum(std::max(ymax1,ymax2));
    mg->SetMinimum(std::min(ymin1,ymin2));
    //c->DrawFrame(xmin1, 0, xmax1, 1.1*std::max(ymax1,ymax2));
    mg->Draw("apl");
    c->Update();
    mg->GetHistogram()->GetXaxis()->SetTitle(xaxis);
    mg->GetHistogram()->GetYaxis()->SetTitle(yaxis);
    c->Modified();

Why are you complicating things when they can be very simple?
Why is the following piece of code not working for you?

Rene

TMultiGraph *mg = new TMultiGraph; mg->SetTitle("title;xaxis title; yaxis title"); mg->Add(g1); mg->Add(g2); mg->Draw("apl");

Hi Rene,

I had no idea that solution existed. Is it anywhere in the documentation?

Thanks!

Alex

Ha very useful. I’ve struggled with this myself. There are many things that ROOT does great once you stumble upon the syntax.

I would recommend this ends up on the root.cern.ch/root/html/TMultiGraph.html page. Like the earlier poster, I’ve spent a fair amount of time looking for just this.

Elliott

I have updated the TMultiGraph doc.