Closed tvami closed 2 weeks ago
Talked with Pritam privately and he agreed to have a look at this.
I've done this so many times, here is the matplotlib code to do a raw/ratio plot.
fig, (raw, ratio) = plt.subplots(
nrows = 2,
sharex = 'col',
height_ratios = [2, 1], # height of raw panel relative to ratio panel
gridspec_kw = dict(
hspace = 0.05 # separation between panels, can be zero to overlap axis lines
)
)
raw.hist(..., label='One')
raw.hist(..., label='Two')
raw.set_ylabel('Events')
raw.legend()
ratio.plot(one/two)
ratio.set_ylabel('Ratio')
ratio.set_xlabel('X Label / Units')
fig.savefig('filename.png', bbox_inches='tight')
fig.close() # only helpful in scripts like Validation where we want to cleanup figures that are done
Nice! I think what I'd like is to have the ratio inserted in the bottom of the canvas just below the main plot. An example:
That is what the above code does. subplots
creates two "axes" in a grid within the "figure".
Vocab Change
matplotlib | ROOT |
---|---|
figure | TCanvas |
axes | TPad |
axis | TAxis |
The code above is basically following this guide but with some extra parameters I've learned while tuning the plots to be closer to what we want.
Ahh perfect, I didnt read it carefully! Will you PR it @tomeichlersmith ?
Got a draft on the attached branch :+1: not sure when I'll get a chance to test it
I can give a try to testing, do you wanna open a draft PR?
Is your feature request related to a problem? Please describe.
Right now the
Validation
module offers to overlay 1D histograms.Describe the solution you'd like
I believe it would be super useful to automatically generate a ratio plot in the bottom of the overlaid plot to show the differences.
Describe alternatives you've considered
One could do this outside of the
Validation
module in a private script, but wouldnt it be easier to do this once and have it in ldmx-sw?