# SetRangeUser is not working for TGraph

**URL:** <https://root-forum.cern.ch/t/setrangeuser-is-not-working-for-tgraph/55533>\
**Category:** ROOT\
**Created:** [July 3, 2023, 6:45pm UTC](https://root-forum.cern.ch/t/setrangeuser-is-not-working-for-tgraph/55533 "2023-07-03T18:45:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charlie](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@Charlie](https://root-forum.cern.ch/u/Charlie)\
**Post date:** [July 3, 2023, 6:45pm UTC](https://root-forum.cern.ch/t/setrangeuser-is-not-working-for-tgraph/55533/1 "2023-07-03T18:45:42Z")

</div>

Hello,

For some reason, SetRangerUser is not working when I’m using TGraph. I’m writing out my code in this way, which works for histogram classes.

```auto
TGraph *g1 = new TGraph();
g1->GetYaxis()->SetRangeUser(0,1);

```

I’ve looked at other forums that discusses the same problem, but it’s still not working. I also want to do this for multiple graphs that be drawn on to the same canvas. So, do I have to do it for one graph or for all of my graphs? Hope to hear a response soon. Thanks in advance.

-Charlie Clark

_ROOT Version:_ 6.26/06  
_Platform:_ MacOS  
_Compiler:_ C++

* * *

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 4, 2023, 4:03am UTC](https://root-forum.cern.ch/t/setrangeuser-is-not-working-for-tgraph/55533/2 "2023-07-04T04:03:39Z")

</div>

For the y-axis, use SetMinimum/Maximum:

```auto
g1->SetMinimum(0);
g1->SetMaximum(1);

```

or you can also do:

```auto
g1->GetHistogram()->GetYaxis()->SetRangeUser(0,1);

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 4, 2023, 8:12am UTC](https://root-forum.cern.ch/t/setrangeuser-is-not-working-for-tgraph/55533/3 "2023-07-04T08:12:01Z")

</div>

> [@How to set ranges on axis?](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/28254):
>
> The viewing range for a histogram axis can be set from bin ifirst to ilast using the method TAxis::SetRange(ifirst, ilast). Example (hpxpy is a 2D histogram): { TFile f("hsimple.root"); hpxpy-\>Draw("colz"); hpxpy-\>GetYaxis()-\>SetRange(22,23); hpxpy-\>GetXaxis()-\>SetRange(18,19); } Sometimes it is more convenient to set this range using “User’s Coordinates” (axis values) rather than bin numbers. To do that one should use TAxis::SetRangeUser(ufirst, ulast). This method computes the cl…

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 18, 2023, 8:12am UTC](https://root-forum.cern.ch/t/setrangeuser-is-not-working-for-tgraph/55533/4 "2023-07-18T08:12:03Z")

</div>

Closed on July 18, 2023, 8:12am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
