Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ratio inset for plots in DQM Validation module #1382

Closed
tvami opened this issue Aug 6, 2024 · 7 comments · Fixed by #1401
Closed

Ratio inset for plots in DQM Validation module #1382

tvami opened this issue Aug 6, 2024 · 7 comments · Fixed by #1401
Assignees

Comments

@tvami
Copy link
Member

tvami commented Aug 6, 2024

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?

@tvami
Copy link
Member Author

tvami commented Aug 13, 2024

Talked with Pritam privately and he agreed to have a look at this.

@tomeichlersmith
Copy link
Member

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

@tvami
Copy link
Member Author

tvami commented Aug 21, 2024

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:
Screenshot 2024-08-21 at 07 37 33

@tomeichlersmith
Copy link
Member

tomeichlersmith commented Aug 21, 2024

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.

@tvami
Copy link
Member Author

tvami commented Aug 21, 2024

Ahh perfect, I didnt read it carefully! Will you PR it @tomeichlersmith ?

@tomeichlersmith
Copy link
Member

Got a draft on the attached branch 👍 not sure when I'll get a chance to test it

@tvami
Copy link
Member Author

tvami commented Aug 21, 2024

I can give a try to testing, do you wanna open a draft PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants