# Y axis range of a displayed histogram

**URL:** <https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [July 15, 2022, 2:28pm UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821 "2022-07-15T14:28:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 15, 2022, 2:28pm UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/1 "2022-07-15T14:28:42Z")

</div>

For getting the range of a histogram on the X axis, I wonder why

```
h.GetXaxis().GetXmin()

```

works, but the same for Y:

```
h.GetYaxis().GetXmin()

```

does not. The class `TAxis` has only `GetX...` because I guess, a `TAxis` is always one dimensional.

It seems that this question has been previously asked [here](https://root.cern.ch/root/roottalk/roottalk04/1754.html) but the answer doesn’t seem to be correct, since `GetMinimum()` and `GetMaximum()` apparently do different things, namely the return the extrema of the content not of the axes.

* * *

_ROOT Version:_ 6.26/04  
_Platform:_ osx  
_Compiler:_ pyroot

* * *

---

<div class="post-metadata">

**Author:** ![RENATO\_QUAGLIANI](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/renato_quagliani/32/19496_2.png) [@RENATO\_QUAGLIANI](https://root-forum.cern.ch/u/RENATO_QUAGLIANI)\
**Post date:** [July 15, 2022, 9:10pm UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/2 "2022-07-15T21:10:52Z")

</div>

I might be wrong, but I think that the yaxis min max as written would work if you draw a TH2D, if you draw a TH1D the pad over which it gets drawn takes as default the histogram Minimum and Maximum\*1.x with X \>0.

If you really need to get the automatically drawn y values min/max on axis, you probably first draw the histogram , then play with the `gPad` axis.

What exactly you need to get from a drawn histogram 1D?

---

<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 16, 2022, 4:10am UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/3 "2022-07-16T04:10:11Z")

</div>

Try, after drawing:

```auto
   gPad->Update();
   cout << gPad->GetFrame()->GetY1() << endl;
   cout << gPad->GetFrame()->GetY2() << endl;

```

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 16, 2022, 9:33am UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/4 "2022-07-16T09:33:54Z")

</div>

thanks! this seems to work!

Now on a very similar case, if the Histogram is still not displayed, but just defined, like:

```
h = TH2F('name', 'title', nbinsx, xlow, xup, nbinsy, ylow, yup)

```

I can use `h.GetNbinsX()`, `h.GetNbinsY()`, `h.GetTitle()` and `h.GetTitle()` to access four of the eight properties. But how can I access `xlow`, `xup`, `ylow` and `yup` after creation of the object?

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 16, 2022, 9:46am UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/5 "2022-07-16T09:46:47Z")

</div>

You can get them using calls from your first post here.

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 16, 2022, 9:59am UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/6 "2022-07-16T09:59:59Z")

</div>

ture, but as I mentioned in the original post, it does not work for Y axis. Something seems to be missing.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 16, 2022, 10:00am UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/7 "2022-07-16T10:00:48Z")

</div>

It should work for a 2d histogram.

---

<div class="post-metadata">

**Author:** ![xaratustra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/xaratustra/32/13212_2.png) [@xaratustra](https://root-forum.cern.ch/u/xaratustra)\
**Post date:** [July 16, 2022, 10:02am UTC](https://root-forum.cern.ch/t/y-axis-range-of-a-displayed-histogram/50821/8 "2022-07-16T10:02:53Z")

</div>

yes you are right. my mistake. thanks.
