# Histogram x-axis range

**URL:** <https://root-forum.cern.ch/t/histogram-x-axis-range/12815>\
**Category:** ROOT\
**Created:** [July 22, 2011, 3:05pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815 "2011-07-22T15:05:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@manoj](https://root-forum.cern.ch/u/manoj)\
**Post date:** [July 22, 2011, 3:05pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/1 "2011-07-22T15:05:10Z")

</div>

Hi,

Is there way to zoom the x-axis viewing range in a histogram? I tried SetRangeUser() but did not work.

Thanks.

---

<div class="post-metadata">

**Author:** ![Stefanos21](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/8e8cbc/32.png) [@Stefanos21](https://root-forum.cern.ch/u/Stefanos21)\
**Post date:** [July 22, 2011, 3:06pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/2 "2011-07-22T15:06:47Z")

</div>

```auto
h->GetXaxis()->SetRangeUser(min, max);

```

---

<div class="post-metadata">

**Author:** ![manoj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@manoj](https://root-forum.cern.ch/u/manoj)\
**Post date:** [July 22, 2011, 3:15pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/3 "2011-07-22T15:15:13Z")

</div>

Thanks. I tried the same thing but did not work. It works for y-axis. Also, it work for TGraph.

---

<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 22, 2011, 3:17pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/4 "2011-07-22T15:17:50Z")

</div>

see [How to set ranges on axis?](https://root-forum.cern.ch/t/how-to-set-ranges-on-axis/28254)

---

<div class="post-metadata">

**Author:** ![manoj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@manoj](https://root-forum.cern.ch/u/manoj)\
**Post date:** [July 22, 2011, 3:22pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/5 "2011-07-22T15:22:27Z")

</div>

Thanks, I appreciate. It is for TGraph. Is there way to set for histogram without converting it to TGraph.

---

<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 22, 2011, 3:25pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/6 "2011-07-22T15:25:41Z")

</div>

On the Y axis for histograms you should use SetMaximum() and SetMinimum() (quite clear from the example I sent)

---

<div class="post-metadata">

**Author:** ![manoj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@manoj](https://root-forum.cern.ch/u/manoj)\
**Post date:** [July 22, 2011, 3:39pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/7 "2011-07-22T15:39:06Z")

</div>

Ok. It seems like h-\>GetXaxis()-\>SetLimits(min, max) works but different way. It does not zoom out the plot, it only zoom in the x-axis. I have attached two plots, before and after h-\>GetXaxis()-\>SetLimits(min, max).

Thanks.[c2.pdf](https://root-forum.cern.ch/uploads/default/original/2X/4/416e01820a1188ec9f8b3f25b22039435580bcda.pdf) (14.1 KB)[c1.pdf](https://root-forum.cern.ch/uploads/default/original/2X/4/44d93ac5fcd4bd83e715f05efc39bbc74e863341.pdf) (13.9 KB)

---

<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 22, 2011, 3:47pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/8 "2011-07-22T15:47:50Z")

</div>

To zoom you should do:

```auto
h->GetXaxis()->SetRangeUser(min,max);

```

SetLImits changes the limits of the histogram but does not zoom. The histograms remains the same only the limits on the axis change.

---

<div class="post-metadata">

**Author:** ![manoj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@manoj](https://root-forum.cern.ch/u/manoj)\
**Post date:** [July 22, 2011, 3:56pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/9 "2011-07-22T15:56:10Z")

</div>

Hi couet,

Right. Unfortunately, h-\>GetXaxis()-\>SetRangeUser(min,max) works if min and max are within the original min and max range. If my original min = -1 and max = 1, then it works if I do SetRangeUser(-0.7, 0.7) but it does not work if I do SetRangeUser(-1.4, 1.4).

---

<div class="post-metadata">

**Author:** ![Stefanos21](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/8e8cbc/32.png) [@Stefanos21](https://root-forum.cern.ch/u/Stefanos21)\
**Post date:** [July 22, 2011, 4:17pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/10 "2011-07-22T16:17:55Z")

</div>

> [@manoj](#):
>
> If my original min = -1 and max = 1, then it works if I do SetRangeUser(-0.7, 0.7) but it does not work if I do SetRangeUser(-1.4, 1.4).

I don’t think you can do this…

---

<div class="post-metadata">

**Author:** ![manoj](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@manoj](https://root-forum.cern.ch/u/manoj)\
**Post date:** [July 22, 2011, 4:45pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/11 "2011-07-22T16:45:12Z")

</div>

> [@Stefanos21](#):
>
> > [@manoj](#):
> >
> > If my original min = -1 and max = 1, then it works if I do SetRangeUser(-0.7, 0.7) but it does not work if I do SetRangeUser(-1.4, 1.4).
> 
> I don’t think you can do this…

Thanks. Any trick?

---

<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 25, 2011, 1:31pm UTC](https://root-forum.cern.ch/t/histogram-x-axis-range/12815/12 "2011-07-25T13:31:33Z")

</div>

You need to re-book and re-fill the histogram. Eventually if you do not know the initial range you can use the buffer (fill with xmin\> xmax).
