SetRangeUser on TGraphs

Hi all,

I’m facing an annoying problem when using the SetRangeUser method on the x-axis of a TGraph. I create a dummy TGraph with the commands:

Double_t x[10] = {1.e-1, 1.e0, 1.e1, 1.e2, 1.e3, 1.e4, 1.e5, 1.e6, 1.e7, 1.e8};
Double_t y[10] = {1.e-1, 1.e0, 1.e1, 1.e2, 1.e3, 1.e4, 1.e5, 1.e6, 1.e7, 1.e8};
TGraph *gr = new TGraph(10, x, y);
gr -> SetMarkerStyle(24);
gr -> Draw(“ap”);

Then I set the Logx and Logy scales on the canvas, to a clearer visualization. Then, I use SetRangeUser(1.e-1, 1.eCool on both the x and y axes, but it works only for the y axis, not for the x one. Could anyone check it?

Thank you,
Antonio

May be this macro can help you:

{
   Int_t n=20;
   Double_t x[n],y[n];
   for (Int_t i=0; i < n; i++) {
      x[i]=i*0.1;
      y[i]=10*sin(x[i]+0.2);
   }
   TGraph *gr1 = new TGraph (n,x,y);
   TAxis *axis = gr1->GetXaxis();

   axis->SetLimits(0.,5.);                 // along X
   gr1->GetHistogram()->SetMaximum(20.);   // along          
   gr1->GetHistogram()->SetMinimum(-20.);  //   Y     

   gr1->Draw("AC*");
}

Occasionally I had this question too. Yes,

can solve this problem, I am still wondering why

is not working for x-axis.

Zhiyi.

OK thanks, your recipes actually work fine for me :slight_smile: