Skip to content

Commit 55f8251

Browse files
Fix matplotlib#28016: wrong lower ylim when baseline=None on stairs.
Instead of assuming that lower ylim=0 when baseline=None it now takes into account the imputed values. Also no longer uses sticky_edges in these cases. Changed the unit test that tested baseline=None.
1 parent d9210df commit 55f8251

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7272,14 +7272,14 @@ def stairs(self, values, edges=None, *,
72727272
"very likely that the resulting fill patterns is not the desired "
72737273
"result."
72747274
)
7275-
if baseline is None:
7276-
baseline = 0
7277-
if orientation == 'vertical':
7278-
patch.sticky_edges.y.append(np.min(baseline))
7279-
self.update_datalim([(edges[0], np.min(baseline))])
7280-
else:
7281-
patch.sticky_edges.x.append(np.min(baseline))
7282-
self.update_datalim([(np.min(baseline), edges[0])])
7275+
7276+
if baseline is not None:
7277+
if orientation == 'vertical':
7278+
patch.sticky_edges.y.append(np.min(baseline))
7279+
self.update_datalim([(edges[0], np.min(baseline))])
7280+
else:
7281+
patch.sticky_edges.x.append(np.min(baseline))
7282+
self.update_datalim([(np.min(baseline), edges[0])])
72837283
self._request_autoscale_view()
72847284
return patch
72857285

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,16 +2449,17 @@ def test_stairs_update(fig_test, fig_ref):
24492449

24502450

24512451
@check_figures_equal(extensions=['png'])
2452-
def test_stairs_baseline_0(fig_test, fig_ref):
2453-
# Test
2454-
test_ax = fig_test.add_subplot()
2455-
test_ax.stairs([5, 6, 7], baseline=None)
2452+
def test_stairs_baseline_None(fig_test, fig_ref):
2453+
x = np.array([0, 2, 3, 5, 10])
2454+
y = np.array([1.148, 1.231, 1.248, 1.25])
2455+
2456+
test_axes = fig_test.add_subplot()
2457+
test_axes.stairs(y, x, baseline=None)
24562458

2457-
# Ref
2458-
ref_ax = fig_ref.add_subplot()
24592459
style = {'solid_joinstyle': 'miter', 'solid_capstyle': 'butt'}
2460-
ref_ax.plot(range(4), [5, 6, 7, 7], drawstyle='steps-post', **style)
2461-
ref_ax.set_ylim(0, None)
2460+
2461+
ref_axes = fig_ref.add_subplot()
2462+
ref_axes.plot(x, np.append(y, y[-1]), drawstyle='steps-post', **style)
24622463

24632464

24642465
def test_stairs_empty():

0 commit comments

Comments
 (0)