# SetLimits on x Axis for MultiGraph

Hi!
I have TMultiGraph with 2 TGraph added
I want to make the X axis staring from 1 and Y not higher then 2, so I tried:
TMultiGraph *mg=new TMultiGraph();
mg->SetMaximum(2);
mg->GetXaxis()->SetLimits(2,5 );
mg->Draw(“aPC”);
But while running it crashes I also tried to set the limits before for gr and gr2 but
than it makes no effect at all
Thanks

You need to set x-axis limits AFTER drawing the object.

1 Like

It would be a nice solution if it worked.
You can try this script and see that SetLimits makes
absolutely no effect on the X scale range. Could anybody
say what can be wrong?

{
gROOT->Reset();
TCanvas *c1 = new TCanvas(“c1”,“A Simple Graph Example”,200,10,700,500);
Int_t n=5;
Int_t x[]={2,4,5,6,7};
Int_t y[]={2,3,2,2,3};
Int_t a[]={1,2,3,4,5};
Int_t b[]={4,5,5,4,5};
TGraph *gr=new TGraph(n,x,y);
TGraph *gr0=new TGraph(n,a,b);
TMultiGraph *mg=new TMultiGraph();
mg->SetTitle(“Multi”);
mg->SetMaximum(10);
mg->SetMinimum(0);

mg->Draw(“ac”);
mg->GetXaxis()->SetLimits(5,10);
}

Of cource, you have either to redraw your multigraph object or add

c1->Modified();

once you have set the limits.

Great! Sorry I should think about it
Thank you!

Doesn’t work with batch mode!
Is there any workaround?
(using ROOT 6.08/06)

For me it works also in batch mode. I am using ROOT 5.34/00.