diff --git a/src/mplhep/plot.py b/src/mplhep/plot.py index f9536879..b534cd94 100644 --- a/src/mplhep/plot.py +++ b/src/mplhep/plot.py @@ -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] diff --git a/tests/baseline/test_hist2dplot_hist_all_flow_hint.png b/tests/baseline/test_hist2dplot_hist_all_flow_hint.png new file mode 100644 index 00000000..c38cde4a Binary files /dev/null and b/tests/baseline/test_hist2dplot_hist_all_flow_hint.png differ diff --git a/tests/baseline/test_hist2dplot_hist_all_flow_show.png b/tests/baseline/test_hist2dplot_hist_all_flow_show.png new file mode 100644 index 00000000..0d23a10a Binary files /dev/null and b/tests/baseline/test_hist2dplot_hist_all_flow_show.png differ diff --git a/tests/test_basic.py b/tests/test_basic.py index c5450bf7..11c1f114 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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)