Y axis range of a displayed histogram

For getting the range of a histogram on the X axis, I wonder why


works, but the same for Y:


does not. The class TAxis has only GetX... because I guess, a TAxis is always one dimensional.

It seems that this question has been previously asked here but the answer doesn’t seem to be correct, since GetMinimum() and GetMaximum() apparently do different things, namely the return the extrema of the content not of the axes.

ROOT Version: 6.26/04
Platform: osx
Compiler: pyroot

I might be wrong, but I think that the yaxis min max as written would work if you draw a TH2D, if you draw a TH1D the pad over which it gets drawn takes as default the histogram Minimum and Maximum*1.x with X >0.

If you really need to get the automatically drawn y values min/max on axis, you probably first draw the histogram , then play with the gPad axis.

What exactly you need to get from a drawn histogram 1D?

1 Like

Try, after drawing:

   cout << gPad->GetFrame()->GetY1() << endl;
   cout << gPad->GetFrame()->GetY2() << endl;
1 Like

thanks! this seems to work!

Now on a very similar case, if the Histogram is still not displayed, but just defined, like:

h = TH2F('name', 'title', nbinsx, xlow, xup, nbinsy, ylow, yup)

I can use h.GetNbinsX(), h.GetNbinsY(), h.GetTitle() and h.GetTitle() to access four of the eight properties. But how can I access xlow, xup, ylow and yup after creation of the object?

You can get them using calls from your first post here.

ture, but as I mentioned in the original post, it does not work for Y axis. Something seems to be missing.

It should work for a 2d histogram.

yes you are right. my mistake. thanks.