# THStack Y-axis range offset

Hello everyone!

I have seen this many times, googled a lot and tested a lot, but I just can’t figure out the issue with the Y-axis range of a THStack.

If you create two identical plots, one with a TH1F and one with the TH1F pushed into a THStack (as a simple example) and set the Maximum value for the Y-axis to the same values, the TH1F displays it correctly, but the THStack has an offset of about 5%.

I have a C++ sample running under root_v5.26.00b-linuxx8664gcc

``````void Minimal() {

//Create some dummy TH1F histogram
TH1F histo("histo","histo", 5, 0.0, 5.0);
histo.Fill(0);
histo.Fill(1);  histo.Fill(1);
histo.Fill(2);  histo.Fill(2);  histo.Fill(2);
histo.Fill(3);  histo.Fill(3);  histo.Fill(4);
histo.SetFillColor(2);

//Push the histogram into a THStack
THStack stack("stack", "stack");

//===== Create output for TH1F =====
TCanvas c1("canvas1", "canvas1", 1024, 768);

c1.cd();

//Set Minimum and Maximum for Y-axis
histo.SetMinimum(0.0);
histo.SetMaximum(5.0);
histo.Draw();

//Update, save and close
c1.Close();

//===== Create output for THStack =====
TCanvas c2("canvas2", "canvas2", 1024, 768);

c2.cd();

//Set Minimum and Maximum for Y-axis
stack.Draw();
stack.SetMinimum(0.0);
stack.SetMaximum(5.0);
//stack.GetHistogram()->SetMaximum(5.0);
//stack.GetHistogram()->GetYaxis()->SetRange(0.0, 5.0);
//stack.GetYaxis()->SetLimits(0.0, 5.0);
//stack.GetHistogram()->GetYaxis()->SetLimits(0.0, 5.0);

//Update, save and close
c2.SaveAs("stack.png");
c2.Close();
}``````

If you run it and look at the outoputs histo.png and stack.png you see a difference. If enabling logscale its even more complicated. Does someone know or have a solution or workaround for this issue?

Cheers
Tobias

I just draw a dummy hist with my axis range and then the stack. Couet has another solution in the post. You can see the code in THStack that is causing you the trouble. The code attempts to automatically set pleasing yaxis limits.

Cheers,
Justin