Home | News | Documentation | Download

Number of bins and range of plot is changed

Hi,
In my histogram, I’m getting a plot with decreased number of bins, and the range from (-1.0, 1.0) is changed to (-1.0, 0.8). I fixed the range of the plot by

h->GetXaxis()->SetRangeUser(-1.0, 1.0);

But I cannot see bins with zero bin content in data. But I want to see those bins also. How to fix this issue?

Thanks

Try with SetLimits instead of SetRangeUser.

Thanks for the help. SetLimits is working fine. But I also want to get missing bins that have zero no. of events or bin content.

What exactly do you mean by “get” missing bins? Can you show what you have and explain what you want?

Be careful that with SetLimits you change the min and max values of the axis. Therefore the X value of each bin changes. Unlike SetRangeUser which allows to see a subrange of the axis. The best would be to provide a small macro showing what you are doing.

histo.C (3.1 KB)
test.C (2.0 KB)

Here “test.C” creating a histogram in “histo.C”. Line 12 and 15 are for booking of histogram for function “costhe”. Line no.23 of “histo.C” shows that now the range is fixed at (-1.0, 1.0) by using SetLimits or SetRangeUser. But I didn’t see any change in bin contents if I choose any command. In “histo.C”, you can see that I’m getting 18 bins out of 20. However, bin no. 19 and 20 are empty but I want to print them also.

Do not use “SetLimits” (it changes the full range which was set at histogram’s creation time).
You do not need “SetRangeUser” (you anyhow want the same range as was set at histogram’s creation time).

Try:
hist_costh->Draw("hist"); hist_costh->Draw("hist same"); // draw it "twice"
or:
hist_costh->SetLineWidth(2); // (2) or (3)