# Yaxis range does not adjust when zooming Xaxis of THStack

**URL:** <https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953>\
**Category:** ROOT\
**Tags:** bug, hist\
**Created:** [January 5, 2021, 2:27pm UTC](https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953 "2021-01-05T14:27:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [January 5, 2021, 2:27pm UTC](https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953/1 "2021-01-05T14:27:47Z")

</div>

If I call `TH1::GetXaxis()->SetRange`, the Yaxis range automatically adjusts to zoom in on the selected bins. For `THStack::GetXaxis()->SetRange`, however, this is not the case–the Yaxis retains the same range it had before. Is there a way to automatically adjust the Yaxis to reflect the new Xaxis range (as for `TH1`), do I have to calculate the proper Yaxis range manually, or is this a bug? Reproducer follows.

* * *

```python
import ROOT as r
h1 = r.TH1F("h1", "h1", 100, 0, 100)
for i in range(int(1e6)):
    h1.Fill(r.gRandom.Gaus(20, 5))
c = r.TCanvas()
h1.Draw() # full range shown

```

[TH1\_FullRange.pdf](https://root-forum.cern.ch/uploads/short-url/ywkTptqAOEKHGMprZXAwt3vpP1d.pdf) (14.2 KB)

```python
h1.GetXaxis().SetRange(1, 6)
c.Update() # Yaxis zooms in to show content in bins 1 to 6

```

[TH1\_Zoomed.pdf](https://root-forum.cern.ch/uploads/short-url/a0q270NNb2GxcnIfgPkZoi0oX5k.pdf) (13.2 KB)

```python
h2 = r.TH1F("h2", "h2", 100, 0, 100)
for i in range(10):
    h2.Fill(r.gRandom.Gaus(9, 5))
hs = r.THStack()
hs.Add(h1)
hs.Add(h2)
hs.Draw() # note Yaxis range

```

[THStack\_FullRange.pdf](https://root-forum.cern.ch/uploads/short-url/1xDSPQqkFjOV4erfPDq9oGDspMA.pdf) (14.5 KB)

```python
hs.GetXaxis().SetRange(1, 6)
c.Update() # Yaxis range has not changed, making it difficult to see the bins

```

[THStack\_Zoomed.pdf](https://root-forum.cern.ch/uploads/short-url/iaxcznZuReQFkYbK6zvu3seAlEV.pdf) (13.5 KB)

* * *

_ROOT Version:_ 6.22/06  
_Platform:_ macOS  
_Compiler:_ Not Provided

* * *

---

<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:** [January 5, 2021, 4:36pm UTC](https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953/2 "2021-01-05T16:36:46Z")

</div>

You are right when I zoom on the X axis interactively (which does `GetXaxis()->SetRange`) the Y axis does not change. This is an issue. I suggest [you open a GitHub issue](https://github.com/root-project/root/issues/new) with that and we will try to fix it.

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [January 5, 2021, 4:54pm UTC](https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953/3 "2021-01-05T16:54:43Z")

</div>

Done. Issue [#6991](https://github.com/root-project/root/issues/6991). In the meantime, is there a workaround or am I stuck manually recalculating?

---

<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:** [January 5, 2021, 5:06pm UTC](https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953/4 "2021-01-05T17:06:06Z")

</div>

I tried a few things but it does not seem there is a simple workaround for this issue.  
Thanks for the GitHub report.

---

<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:** [January 19, 2021, 5:06pm UTC](https://root-forum.cern.ch/t/yaxis-range-does-not-adjust-when-zooming-xaxis-of-thstack/42953/5 "2021-01-19T17:06:10Z")

</div>

Closed on January 19, 2021, 5:06pm UTC

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