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

Including ratio subplot within differ when comparing #1401

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions Validation/src/Validation/_differ.py
Original file line number Diff line number Diff line change
@@ -108,30 +108,47 @@ def plot1d(self, column, xlabel,
All other key-word arguments are passed into each File.plot1d
"""
fig = plt.figure('differ',figsize=(11,8))
ax = fig.subplots()

raw_ax, ratio_ax = fig.subplots(
nrows = 2,
sharex = 'col',
height_ratios = [2, 1],
gridspec_kw = dict(
hspace = 0.05
)
)

raw_histograms = []
for f in self.files :
try:
weights, bins, patches = f.plot1d(ax, column, **hist_kwargs)
raw_histograms.append(f.plot1d(raw_ax, column, **hist_kwargs))
except uproot.KeyInFileError:
f.log.warn(f"Key {column} doesn't exist in {self}, skipping")
continue

ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_yscale(yscale)
ax.set_ylim(*ylim)
raw_ax.set_ylabel(ylabel)
raw_ax.set_yscale(yscale)
raw_ax.set_ylim(*ylim)

if 'title' not in legend_kw :
legend_kw['title'] = self.grp_name

if tick_labels is not None:
ax.set_xticks((bins[1:]+bins[:-1])/2)
ax.set_xticklabels(tick_labels)
ax.tick_params(axis='x', rotation=90)
raw_ax.legend(**legend_kw)

denominator, bins, _denominator_art = raw_histograms[0]
bin_centers = (bins[1:]+bins[:-1])/2
for values, _bins, art in raw_histograms[1:]:
ratio_ax.scatter(
bin_centers,
values/denominator,
color = art[0].get_edgecolor()
)

ax.legend(**legend_kw)
ratio_ax.set_ylabel('Ratio')
ratio_ax.set_xlabel(xlabel)
if tick_labels is not None:
ratio_ax.set_xticks((bins[1:]+bins[:-1])/2)
ratio_ax.set_xticklabels(tick_labels)
ratio_ax.tick_params(axis='x', rotation=90)

if out_dir is None :
plt.show()
Loading