SetRangeUser without SetMin/SetMax on histogram

Dear ROOTers,

For purpose of display, I need to use SetRangeUser on the Y-axis of an histogram. I do not want however that the values for the Minimum/Maximum of the histogram be altered by this change (as I just discovered is done automatically:

How should I get around to do this? Also incidentally, why is SetRangeUser, a function member of TAxis, modifying the content of the TH1 object?

Many thanks in advance for your help!


For changing the range of the histogram content you should use SetMinimum/SetMaximum and not the Y axis.
The Y axis should be used for a 2D histogram.
The given example intact refers to a 2d histogram.


Dear Lorenzo,

Thanks for taking the time to reply to my request, but this is precisely the inverse of what I am attempting to do. I want the display range to be modified without changing the histogram object content (in particular, the maximum or minimum information).




I don;t understand your problem. SetMinimum/SetMaximum do not change the histogram content, but just the display range.


I think maybe this is related to the confusion between TH1::GetMinimum and TH1::GetBinContent + TH1::GetMinimumBin, and the similar GetMaximum methods.

Using SetMaximum/SetMinimum does change the result of one of those, making it appear that the histogram contents are changed. Related to the semi-rhetorical question in the original post, I think this is an example of the detrimental mixing of the plotting and histogramming facilities of TH1. The answer to “why is it this way” is usually just “because that’s how it was coded a while ago and its too late to change it now”.


Dear Lorenzo and Jean-François,

The minimum and maximum values of a histogram are effectively member of the TH1 object, so by changing them when I do SetRangeUser, I modify the original value stored in these members without a real need for it. Hence my point about changing the histogram “content”

Thanks Jean-François for this feedback! Although my question may have sounded rhetorical, I am really trying to understand why a function of TAxis (and not overloaded by TH1) has any impact on TH1. I would have naively expected that SetRangeUser would have modified the range of the axis without affecting the TH1 members.

Which brings me to my other question: how do go around this? Is there any way to simply modify the plotting range of an axis without modify the maximum/minimum of a TH1?

Many thanks for your replies!


Dear Andree

I agree with you about changing data members of the histograms using the axis. This is probably historically, but in my opinion to change the y display range of an histogram, one should not go via the Y axis. A 1d-histogram should have only the X-axis.
We will consider this , when doing a new version of the histogram, but now it is difficult to change the behaviour without upsetting many users using this functionality.

Best Regards


Thanks for taking this into consideration! I understand that this might be tricky.

One question though that might help me in my project. When the function Draw() is called on a 1-D histogram the first time, the range of the y-axis is automatically set to allow some buffer space on top of the maximum of the histo, without changing its value. How is that done? Could I reproduce that in my code?



Set them to -1, then it will be again “automatic”.