From 10e7a262cdc150924a3ade5b76c474e379098216 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 3 Mar 2022 17:34:54 -0500 Subject: [PATCH] Backport PR #22559: fix: fill stairs should have lw=0 instead of edgecolor="none" --- .../modify_stairs_fill_edge_behaviour.rst | 9 +++++++++ lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/tests/test_axes.py | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 doc/users/next_whats_new/modify_stairs_fill_edge_behaviour.rst diff --git a/doc/users/next_whats_new/modify_stairs_fill_edge_behaviour.rst b/doc/users/next_whats_new/modify_stairs_fill_edge_behaviour.rst new file mode 100644 index 000000000000..17ba718750d5 --- /dev/null +++ b/doc/users/next_whats_new/modify_stairs_fill_edge_behaviour.rst @@ -0,0 +1,9 @@ +stairs(..., fill=True) to hide patch edge by setting lw=0 +--------------------------------------------------------- + +``stairs(..., fill=True)`` would previously hide Patch +edge by setting edgecolor="none". Calling ``set_color()`` +on the Patch after would make the Patch appear larger. +Updated treatment prevents this. Likewise calling +``stairs(..., fill=True, lw=3)`` will behave more +transparently. \ No newline at end of file diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index ad5f339dcdc7..1655a9dbc9e5 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6853,7 +6853,7 @@ def stairs(self, values, edges=None, *, else: _color = self._get_lines.get_next_color() if fill: - kwargs.setdefault('edgecolor', 'none') + kwargs.setdefault('linewidth', 0) kwargs.setdefault('facecolor', _color) else: kwargs.setdefault('edgecolor', _color) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 204e3cbd984f..bcf8f7b59bb4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2070,7 +2070,7 @@ def test_stairs_options(): ax.stairs(y[::-1]*3+14, x, baseline=26, color='purple', ls='--', lw=2, label="F") ax.stairs(yn[::-1]*3+15, x+1, baseline=np.linspace(27, 25, len(y)), - color='blue', ls='--', lw=2, label="G", fill=True) + color='blue', ls='--', label="G", fill=True) ax.stairs(y[:-1][::-1]*2+11, x[:-1]+0.5, color='black', ls='--', lw=2, baseline=12, hatch='//', label="H") ax.legend(loc=0) @@ -2085,6 +2085,18 @@ def test_stairs_datetime(): plt.xticks(rotation=30) +@check_figures_equal(extensions=['png']) +def test_stairs_edge_handling(fig_test, fig_ref): + # Test + test_ax = fig_test.add_subplot() + test_ax.stairs([1, 2, 3], color='red', fill=True) + + # Ref + ref_ax = fig_ref.add_subplot() + st = ref_ax.stairs([1, 2, 3], fill=True) + st.set_color('red') + + def contour_dat(): x = np.linspace(-3, 5, 150) y = np.linspace(-3, 5, 120)