Setting axis ranges for two TGraphErrors

Hi,

I am new to root. I can plot two TGraphErrors on the same axes with the code below and set the range of the x-axis with the gr1->GetXaxis()->SetLimits( 3660, 3700); statement. But when I try to do the same thing for the y-axis nothing happens, although I don’t get an error message, the axis keeps the same range displayed. Can someone tell me how I can set the y-axis range?

 TGraphErrors* gr1 = new TGraphErrors(n, cm_energyMeV, scaled_xsec, 0, scaled_xerr);
   gr1->SetTitle("Cross-Section at the    #psi '");
    gr1->Draw("AP");
    TGraphErrors* gr2 = new TGraphErrors(j, nk_cm_energyMeV, nk_scaled_xsec, 0, nk_scaled_xerr);
    gr2->SetTitle("Cross-Section at the    #psi '");
    gr2->Draw("P");
    c3->Update();
    gr1->GetXaxis()->SetLimits( 3660, 3700);
    gr1->GetYaxis()->SetLimits( 0, 1900);
    gr1->Draw("AP");
    gr2->Draw("P");
    c3->Update();

Thanks,
Matt :smiley:

Hi,

I can reproduce this with 2 TH2Fs in one Canvas (one pad each), rightclicking on the yaxis, SetRangeUser - and nothing happens. 1FH2F per canvas works just fine. CVS version from last week, linux build=debug.
Axel.

Use SetMinimum/SetMaximum for the axis corresponding to the data.
TGraph and TH1 behave in the same way.

Rene

Thanks your Root supporting. :smiley:

SetRangeUser and SetLimits can not zoom Yaxis of TGraph as
shown in an attached eps file that is obtained by
the sample code at the following condition:
Root Version 4.00/06 11 August 2004
CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004
Linux version 2.4.19-0vl11
gcc version 2.95.3

Thanks,

Yuki
testrange.c (443 Bytes)

Hi Juki,

You should call
gr->SetMinimum(3);
gr->SetMaximum(8);

instead of
gr->GetYaxis()->SetRangeUser( 3, 8 );

I will add support for SetRangeUser for the Y axis in a coming version to get more symmetry with the x axis.

Rene

Hi Brun,

Thank you for your quick response. :smiley:

I will select data-points for SetPoint() by myself until
your symmetry axis X-Y version.
Adding selection codes may be easy to user, however your new
version will increase functionality of TGraph in
browsing and data selection. =D>

Thanks,

Yuki

Now implemented in the CVS version

Rene