Skip to content

Backport PR #22559 on branch v3.5.x (fix: fill stairs should have lw=0 instead of edgecolor="none") #22593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down