Setting a viewing range with arbitrary values

Dear all,

Is it possible to set the viewing range of a histogram with arbitray min/max values?
It seems that the min/max values can be only set to the bin edges.
I want to set the ranges of two or more histograms to the exactly same values for comparison.

Thank you.

use hist.GetXaxis()->SetRange(binmin,binmax)
or
hist.GetXaxis()->SetRangeUser(xmin,xmax)

Rene

Thank you for your reply.

Is it REALLY possible to set an arbitrary viewing range?
I mean, I want to set the xmin/xmax to the value other than bin edges, but as shown in the example below, the xmin/xmax seem to be forced to be bin edges.

root [0] TH1F h("h", "test", 5, 0, 5)
root [1] h.Draw()
root [4] h.GetXaxis()->SetRangeUser(0.5, 4.2)
root [5] gPad->Modified()   // !! viewing range does not change!!

What I want to do is to set the viewing ranges of two histograms with different binning to the same for easy comparison.

When calling SetRangeUser, ROOT calculates the bin number that includes the extreme values. It cannot do anything else.
If what you want to do is simply to set the pad range, you can for example use TPad::DrawFrame

TCanvas c1 c1.DrawFrame(xmin,ymin,xmax,ymax); h.Draw();
Rene

Unfortunatelly this solution cannot be used for contour plots, because “cont4” does not work with “same” option and “cont” does not plot correct contours…

I have been desperate for the improvement of the contour plot for many years…

OK this second problem has nothing to do with your original posting.
Please be specific when posting to this site.
In particular could you post a working script showing the problem with option “cont” ?
One more remark: Given the fact that you store your data in bins, it is obvious that ROOT cannot create energy as it ignores the internal distribution in your bins at the boundaries.

Rene

It does relate closely with the first post.
I take it the solution you wrote is to set the viewing range by first calling TPad::DrawFrame(xmin, ymin, xmax, ymax) and then overlay the histogram with “same” option as below:

root[] TH1F h("h", "test", 5, 0, 5); root[] gPad->DrawFrame(0.5, 4.2); root[] h.Draw("same"); .
But this does not work for a 2D histogram plotted with “cont4” option.
Please try the attached script to see this.

This has been reported at
root.cern.ch/phpBB2/viewtopic.ph … ight=cont4,
root.cern.ch/phpBB2/viewtopic.ph … ight=cont4, and I have been faced with the same problem many times.
cont4.C (17.5 KB)

[quote]
One more remark: Given the fact that you store your data in bins, it is obvious that ROOT cannot create energy as it ignores the internal distribution in your bins at the boundaries. [/quote]
I can understand that, but is it very difficult to just limt the “visible” area to a given range?
I guess that showing multiple histograms with a common range is a common requirement in reports or papers…