Yaxis range does not adjust when zooming Xaxis of THStack

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.

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 (14.2 KB)

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

TH1_Zoomed.pdf (13.2 KB)

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

THStack_FullRange.pdf (14.5 KB)

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

THStack_Zoomed.pdf (13.5 KB)

ROOT Version: 6.22/06
Platform: macOS
Compiler: Not Provided

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 with that and we will try to fix it.

Done. Issue #6991. In the meantime, is there a workaround or am I stuck manually recalculating?

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

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