I have a simple question which I could not find the answer to. I want to draw a histogram ratio plot as bars starting from the line y=1. My code lines look as follows (hist1 and hist2 are TH1D objects):
Setting the option "ep" draws points with error bars. I have tried calling "hist", but the problem is that the bars start from the line y=0. Essentially I would like to to obtain something line this:
Thanks for the suggestion @couet, your link sends me to the function SetH1DrawOpt(); do you mean that by calling it I will automatically obtain bars as histograms? Wouldnât there perhaps be a simple way of âshiftingâ vertically my ratio plot so that the bottom is at 1?
I have already customised a second ratio plot (as dots with error bars) using the Divide function, and I believe it would take me a while until I translate all details to TRatioPlot, but if there is no direct way of doing this with my method I will then give TRatioPlot a try
Hi @couet, here is a reproducer of my current method (with customisations) in case you want to have a look: example_plot.py (2.8 KB)
One possible idea that came to mind is to subtract a dummy histogram [1,⌠, 1] from the ratio plot so that I would obtain the desired bars, although they would start from 0 and not from 1, ideally I would then âshiftâ the y-axis by -1, but I would not know how to do this in ROOT.
Thanks for your code. I thought you were using TRatioPlot, but indeed you are doing your own âratio plotâ. Thatâs fine. In your script, the bottom plot is produce with:
ratiosSM.Draw("hist")
Yes you can shift by -1 the top plot. For instance with:
for (int i = 1; i <= hist->GetNbinsX(); i++) ratiosSM>SetBinContent(i, ratiosSM->GetBinContent(i)-1);
Thanks a lot @couet, that worked perfectly! One last question I would have is if there is a way of âshiftingâ the y-axis values by -1? Perhaps with ratiosSM.GetYaxis()?
The axis labels are automatically computed according to the histogram contain.
The only trick you can do is to use ChangeLabel to define the label you want⌠but thatâs
will not be automatic anymore.