Skip to content

THStack::GetXaxis->SetRange does not auto-zoom Yaxis range #6991

@goi42

Description

@goi42
  • Checked for duplicates

Describe the bug

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.

Originally reported in the forum.

Expected behavior

THStack::GetXaxis()->SetRange should result in a re-zoom of the Yaxis so that the bins in-range are visible.

To Reproduce

See forum.

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
h1.GetXaxis().SetRange(1, 6)
c.Update()  # Yaxis zooms in to show content in bins 1 to 6
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
hs.GetXaxis().SetRange(1, 6)
c.Update()  # Yaxis range has not changed, making it difficult to see the bins

Setup

ROOT Version: 6.22/06
Platform: macOS
Compiler: conda-forge

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions