From f6c9542b291a3687dce9bcdbf725630ee6f16205 Mon Sep 17 00:00:00 2001 From: Johannes Schumann Date: Tue, 30 Apr 2024 15:13:39 +0200 Subject: [PATCH] fix: legend linestyle for step histogram (#496) * forward linestyle to _e_leg and remove xerr * fix exception if no linestyle is given * update test --- src/mplhep/plot.py | 3 ++- tests/test_mock.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mplhep/plot.py b/src/mplhep/plot.py index ea4b9caf..d24083ed 100644 --- a/src/mplhep/plot.py +++ b/src/mplhep/plot.py @@ -416,6 +416,7 @@ def iterable_not_string(arg): if do_errors: _kwargs = soft_update_kwargs(_kwargs, {"color": _s.get_edgecolor()}) + _ls = _kwargs.pop("linestyle", "-") _kwargs["linestyle"] = "none" _plot_info = plottables[i].to_errorbar() _e = ax.errorbar( @@ -423,7 +424,7 @@ def iterable_not_string(arg): **_kwargs, ) _e_leg = ax.errorbar( - [], [], yerr=1, xerr=1, color=_s.get_edgecolor(), label=_label + [], [], yerr=1, xerr=None, color=_s.get_edgecolor(), label=_label, linestyle=_ls ) return_artists.append( StairsArtists( diff --git a/tests/test_mock.py b/tests/test_mock.py index f275c62e..d9db3e1a 100644 --- a/tests/test_mock.py +++ b/tests/test_mock.py @@ -56,7 +56,8 @@ def test_simple(mock_matplotlib): approx([]), approx([]), yerr=1, - xerr=1, + xerr=None, + linestyle='-', color=ax.stairs().get_edgecolor(), label="X", )