# SetRangeUser doesn't work well

**URL:** <https://root-forum.cern.ch/t/setrangeuser-doesnt-work-well/14774>\
**Category:** ROOT\
**Created:** [August 15, 2012, 11:05pm UTC](https://root-forum.cern.ch/t/setrangeuser-doesnt-work-well/14774 "2012-08-15T23:05:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guanfada](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/91b2a8/32.png) [@guanfada](https://root-forum.cern.ch/u/guanfada)\
**Post date:** [August 15, 2012, 11:05pm UTC](https://root-forum.cern.ch/t/setrangeuser-doesnt-work-well/14774/1 "2012-08-15T23:05:36Z")

</div>

I want to use SetRangeUser to limit the range of axis, however, I got a very strange result.  
It works fine for y axis, but not for x axis.

Assuming the range x of my graph is -15 cm to 15 cm, and now if

axis-\>SetRangeUser(-25.0, 25.0); //doesn’t work at all

else if

axis-\>SetRangeUser(-10.0, 25.0); //works fine for left part

else if

axis-\>SetRangeUser(-25.0, 10.0); //works fine for right part

else if

axis-\>SetRangeUser(-10.0, 10.0); //works fine for double sides

Below is the code I used.

Thanks a lot.

[code] const Int\_t n = 100;//number of points

Double\_t x[n], y[n];//array to store coordinates of points  
Double\_t xx[n], yy[n];//array to store coordinates of points

Double\_t theta, rho; //polar coordinate, angle and radius

const Double\_t cm = 10.0;  
for(Int\_t i = 0; i!=n; i++)  
{  
theta = i_2_TMath::Pi()/n;  
//here I use 2250 to make x and y range is [-15 cm, 15 cm]  
rho = std::sqrt(2250_cm_cm/(17-16\*sin(theta)\*sqrt( cos(theta)\*cos(theta) ) ) );

```
x[i] = rho*cos(theta);
y[i] = rho*sin(theta);

xx[i] = x[i]/cm;
yy[i] = y[i]/cm;

```

// std::cout\<\<"(x,y)\_"\<\< i \<\<": " \<\<"(" \<\< x[i]/cm \<\<","\<\<y[i]/cm \<\< “) cm”\<\<std::endl;

}

TCanvas\* c1 = new TCanvas(“c1”, “a heart”, 200, 200, 500, 500);

// TGraph\* graph01 = new TGraph(n,x,y);  
TGraph\* graph01 = new TGraph(n,xx,yy);//for the plot, the unit on each axis is cm

graph01-\>SetTitle(“heart”);

TAxis\* axis = graph01-\>GetXaxis();  
axis-\>SetTitle(“x(cm)”);  
axis-\>CenterTitle(kTRUE);  
axis-\>SetTitleOffset(1.1);  
axis-\>SetRangeUser(-25.0, 25.0);

axis = graph01-\>GetYaxis();  
axis-\>SetTitle(“y(cm)”);  
axis-\>CenterTitle(kTRUE);  
axis-\>SetTitleOffset(1.1);  
axis-\>SetRangeUser(-25.0, 25.0);

graph01-\>SetMarkerColor(2);  
graph01-\>SetMarkerStyle(1);  
graph01-\>SetLineWidth(10);  
graph01-\>SetLineColor(2);

graph01-\>Draw(“AC\*”);[/code]  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/c/cc78d27165fec2d209f7879d446d9970fbb47d26.jpg)

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 16, 2012, 9:16am UTC](https://root-forum.cern.ch/t/setrangeuser-doesnt-work-well/14774/2 "2012-08-16T09:16:10Z")

</div>

Try:  
MyGraph-\>GetXaxis()-\>SetLimits(xmin, xmax);  
MyGraph-\>GetYaxis()-\>SetRangeUser(ymin, ymax);  
or:  
MyGraph-\>GetXaxis()-\>SetLimits(xmin, xmax);  
MyGraph-\>GetHistogram()-\>SetMinimum(ymin);  
MyGraph-\>GetHistogram()-\>SetMaximum(ymax);

See also [url][Drawing a TGraphAsymmErrors](https://root-forum.cern.ch/t/drawing-a-tgraphasymmerrors/14205/1) and [url][SetAxisRange(0.0,1.0,"Y"); is ineffective](https://root-forum.cern.ch/t/setaxisrange-0-0-1-0-y-is-ineffective/14040/1)
