Difference

Setup
# Generate dummy data
x1 = np.r_[np.random.normal(0.4, 0.1, 5000), np.random.normal(0.7, 0.1, 5000)]
x2 = np.r_[np.random.normal(0.4, 0.1, 1000), np.random.normal(0.7, 0.11, 7000)]
# Create and fill histograms
h1 = hist.new.Regular(50, 0, 1).Weight().fill(x1)
h2 = hist.new.Regular(50, 0, 1).Weight().fill(x2)
Code
fig, ax_main, ax_comparison = mh.comp.hists(
h1,
h2,
xlabel="Variable",
ylabel="Entries",
h1_label=r"$h_1$",
h2_label=r"$h_2$",
comparison="difference", # <--
)
mh.add_text(
"Comparison of two hist with difference plot",
ax=ax_main,
fontsize="small",
loc="over left",
)
mh.add_text("Difference ax", ax=ax_comparison, loc="over right", fontsize="small")
Full code
import hist
import numpy as np
import mplhep as mh
np.random.seed(42)
# Generate dummy data
x1 = np.r_[np.random.normal(0.4, 0.1, 5000), np.random.normal(0.7, 0.1, 5000)]
x2 = np.r_[np.random.normal(0.4, 0.1, 1000), np.random.normal(0.7, 0.11, 7000)]
# Create and fill histograms
h1 = hist.new.Regular(50, 0, 1).Weight().fill(x1)
h2 = hist.new.Regular(50, 0, 1).Weight().fill(x2)
fig, ax_main, ax_comparison = mh.comp.hists(
h1,
h2,
xlabel="Variable",
ylabel="Entries",
h1_label=r"$h_1$",
h2_label=r"$h_2$",
comparison="difference", # <--
)
mh.add_text(
"Comparison of two hist with difference plot",
ax=ax_main,
fontsize="small",
loc="over left",
)
mh.add_text("Difference ax", ax=ax_comparison, loc="over right", fontsize="small")