From 58a9b1b60bd1fe19859e03983c46208c6b0b80e6 Mon Sep 17 00:00:00 2001 From: Tristan Fillinger Date: Thu, 24 Oct 2024 18:26:36 +0900 Subject: [PATCH] fix: if available, yerr is shown by default for step histtype --- src/mplhep/plot.py | 8 ++++---- tests/test_basic.py | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mplhep/plot.py b/src/mplhep/plot.py index ef3b79a5..53b8c491 100644 --- a/src/mplhep/plot.py +++ b/src/mplhep/plot.py @@ -442,10 +442,10 @@ def iterable_not_string(arg): if "step" in histtype: for i in range(len(plottables)): - if isinstance(yerr, bool) and yerr and plottables[i].variances is not None: - do_errors = True - else: - do_errors = yerr is not False and (yerr is not None or w2 is not None) + do_errors = yerr is not False and ( + (yerr is not None or w2 is not None) + or (plottables[i].variances is not None) + ) _kwargs = _chunked_kwargs[i] diff --git a/tests/test_basic.py b/tests/test_basic.py index ed5024cd..63fb8880 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -78,7 +78,7 @@ def test_onebin_hist(): fig, axs = plt.subplots() h = hist.Hist(hist.axis.Regular(1, 0, 1)) h.fill([-1, 0.5]) - hep.histplot(h, yerr=True, ax=axs) + hep.histplot(h, ax=axs) return fig @@ -138,10 +138,10 @@ def test_histplot_flow(): fig, axs = plt.subplots(2, 2, sharey=True, figsize=(10, 10)) axs = axs.flatten() - hep.histplot(h, ax=axs[0], yerr=True, flow="hint") - hep.histplot(h, ax=axs[1], yerr=True, flow="show") - hep.histplot(h, ax=axs[2], yerr=True, flow="sum") - hep.histplot(h, ax=axs[3], yerr=True, flow=None) + hep.histplot(h, ax=axs[0], flow="hint") + hep.histplot(h, ax=axs[1], flow="show") + hep.histplot(h, ax=axs[2], flow="sum") + hep.histplot(h, ax=axs[3], flow=None) axs[0].set_title("Default(hint)", fontsize=18) axs[1].set_title("Show", fontsize=18) @@ -213,10 +213,10 @@ def test_histplot_uproot_flow(): fig, axs = plt.subplots(2, 2, sharey=True, figsize=(10, 10)) axs = axs.flatten() - hep.histplot(h, ax=axs[0], yerr=True, flow="show") - hep.histplot(h2, ax=axs[1], yerr=True, flow="show") - hep.histplot(h3, ax=axs[2], yerr=True, flow="show") - hep.histplot(h4, ax=axs[3], yerr=True, flow="show") + hep.histplot(h, ax=axs[0], flow="show") + hep.histplot(h2, ax=axs[1], flow="show") + hep.histplot(h3, ax=axs[2], flow="show") + hep.histplot(h4, ax=axs[3], flow="show") axs[0].set_title("Two-side overflow", fontsize=18) axs[1].set_title("Left-side overflow", fontsize=18) @@ -648,7 +648,7 @@ def test_histplot_bar(): axs[1].set_title("Histtype barstep", fontsize=18) hep.histplot( - [h1, h2, h3], bins, histtype="barstep", label=["h1", "h2", "h3"], ax=axs[1] + [h1, h2, h3], bins, histtype="barstep", yerr=False, label=["h1", "h2", "h3"], ax=axs[1] ) axs[1].legend()