THStack - What is the correct way to set the Y Axis Limits?

I’m trying to track down the source of a crash in a drawing macro.

My question is: What is the “correct / ROOT approved” way to set the y axis range to fixed values, when drawing THStack objects.

Below is an example. The axis range for the top most figure should be fixed to [0.0, 1000.0], however they are not. You can clearly see that the maximum y axis value exceeds 1000.0.

I suspect this is a bug, but I do not know for sure.

In this example I have used


I will try and update this with a MWE, however this will take some time.

In this next figure, I have removed calls to ->Draw() for the other objects drawn on the top figure, such that only the THStack is drawn.

I did this to check that nothing else is being drawn and “disturbing” the maximum axis value.

Can you provide a small example reproducing the issue ?

Does this mean that this the behaviour seen here is not common to all code drawing THStacks?

Thanks for your replies so far by the way, I know you’ve replied to a few of my threads.

I will try and get you a MWE.

here is an example:

void hstackrange()
   THStack *hs = new THStack("hs","test stacked histograms");

   TH1F *h1 = new TH1F("h1","test hstack",100,-4,4);
   TH1F *h2 = new TH1F("h2","test hstack",100,-4,4);
   TH1F *h3 = new TH1F("h3","test hstack",100,-4,4);

   TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,1000,800);

This example has the same bug I am experiencing.

The maximum is not 600. It is about 650.

The trick:


Ok thanks for the info… Why isn’t this the default behaviour, considering that the margin is presumably zero for all other histogram objects which can be drawn.

… at least I have never noticed this issue with any other type of histogram.

Why is the default different in the case of THStack?

Can you change the default to zero for a future release? Because having the behaviour change in a seemingly random way is quite frustrating.

it is the same for all histograms. Put that in your rootlogon.C ?

It definitly isn’t.

If I do

TH1D *h = ...

My axis will be exactly in the range [0.0, 1000.0].

Hence why I assumed this is a bug - well it is a bug, because a software library shouldn’t change it’s behaviour in an inconsistent way like this.

I mean before setting min and max it applies to all histograms. But a THstack is not an histogram.
Let me see if I can do something to change this feature.

Ok thanks. Removing inconsistencies such as this one is really going to help a lot of people.

By the way, I have noticed that some thing seem to only be “settable” with gStyle… I don’t know if this is something you are working towards, but ideally it would be nice to be able to set everything that can be set with gStyle to objects individually.

Again, it would increase the consistency of the libary, as least insofaras the user is concerned.

No it is not planed because it does not alway makes sense.

Ok, fair enough.

May i suggest you open a Github issue with this ? The code is explicitly implemented like that and It would need a close investigation to change its behaviour.

Sure thing, I will do it shortly

Thanks, I will continue the follow up from there.

fixed in

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