Skip to content

Commit

Permalink
feat: add 2d flow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejnovak committed Apr 1, 2024
1 parent ba1aab8 commit f3ad6af
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/mplhep/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,15 +689,6 @@ def hist2dplot(
f"Warning: {type(h)} is not allowed to get flow bins, flow bin option set to None"
)
flow = None
elif (
hasattr(h, "axes")
and hasattr(h.axes[0], "traits")
and hasattr(h.axes[0].traits, "underflow")
and not h.axes[0].traits.underflow
and not h.axes[0].traits.overflow
):
flow = None
print(f"Warning: you don't have flow bins stored in {h}")
elif flow in ["hint", "show"]:
xwidth, ywidth = (xbins[-1] - xbins[0]) * 0.05, (ybins[-1] - ybins[0]) * 0.05
pxbins = np.r_[xbins[0] - xwidth, xbins, xbins[-1] + xwidth]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,62 @@ def test_histplot_type_flow():
return fig


@pytest.mark.mpl_image_compare(style="default")
def test_hist2dplot_hist_all_flow_show():
flow_opts = []
for ufl1 in [True, False]:
for ofl1 in [True, False]:
for ufl2 in [True, False]:
for ofl2 in [True, False]:
flow_opts.append([ufl1, ofl1, ufl2, ofl2])

np.random.seed(0)
_fill = np.random.normal(2.5, 2, 10000).reshape(-1, 2).T
fig, axs = plt.subplots(4, 4)
axs = axs.flatten()
for i, opt in enumerate(flow_opts):
h = (
hist.new.Reg(5, 0, 5, overflow=opt[0], underflow=opt[1])
.Reg(5, 0, 5, overflow=opt[2], underflow=opt[3])
.Weight()
.fill(*_fill)
)
hep.hist2dplot(h, ax=axs[i], flow="show", cbar=False)
axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].set_xlabel("")
axs[i].set_ylabel("")
return fig


@pytest.mark.mpl_image_compare(style="default")
def test_hist2dplot_hist_all_flow_hint():
flow_opts = []
for ufl1 in [True, False]:
for ofl1 in [True, False]:
for ufl2 in [True, False]:
for ofl2 in [True, False]:
flow_opts.append([ufl1, ofl1, ufl2, ofl2])

np.random.seed(0)
_fill = np.random.normal(2.5, 2, 10000).reshape(-1, 2).T
fig, axs = plt.subplots(4, 4)
axs = axs.flatten()
for i, opt in enumerate(flow_opts):
h = (
hist.new.Reg(5, 0, 5, overflow=opt[0], underflow=opt[1])
.Reg(5, 0, 5, overflow=opt[2], underflow=opt[3])
.Weight()
.fill(*_fill)
)
hep.hist2dplot(h, ax=axs[i], flow="hint", cbar=False)
axs[i].set_xticks([])
axs[i].set_yticks([])
axs[i].set_xlabel("")
axs[i].set_ylabel("")
return fig


@pytest.mark.mpl_image_compare(style="default", remove_text=True)
def test_histplot_multiple():
np.random.seed(0)
Expand Down

0 comments on commit f3ad6af

Please sign in to comment.