Skip to content

Commit 3a6f5cd

Browse files
authored
Merge pull request matplotlib#28030 from DiogoCasteloCardoso/main
Fix matplotlib#28016: wrong lower ylim when baseline=None on stairs
2 parents cebc4d8 + 55f8251 commit 3a6f5cd

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
@@ -7268,14 +7268,14 @@ def stairs(self, values, edges=None, *,
72687268
"very likely that the resulting fill patterns is not the desired "
72697269
"result."
72707270
)
7271-
if baseline is None:
7272-
baseline = 0
7273-
if orientation == 'vertical':
7274-
patch.sticky_edges.y.append(np.min(baseline))
7275-
self.update_datalim([(edges[0], np.min(baseline))])
7276-
else:
7277-
patch.sticky_edges.x.append(np.min(baseline))
7278-
self.update_datalim([(np.min(baseline), edges[0])])
7271+
7272+
if baseline is not None:
7273+
if orientation == 'vertical':
7274+
patch.sticky_edges.y.append(np.min(baseline))
7275+
self.update_datalim([(edges[0], np.min(baseline))])
7276+
else:
7277+
patch.sticky_edges.x.append(np.min(baseline))
7278+
self.update_datalim([(np.min(baseline), edges[0])])
72797279
self._request_autoscale_view()
72807280
return patch
72817281

lib/matplotlib/tests/test_axes.py

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

24802480

24812481
@check_figures_equal(extensions=['png'])
2482-
def test_stairs_baseline_0(fig_test, fig_ref):
2483-
# Test
2484-
test_ax = fig_test.add_subplot()
2485-
test_ax.stairs([5, 6, 7], baseline=None)
2482+
def test_stairs_baseline_None(fig_test, fig_ref):
2483+
x = np.array([0, 2, 3, 5, 10])
2484+
y = np.array([1.148, 1.231, 1.248, 1.25])
2485+
2486+
test_axes = fig_test.add_subplot()
2487+
test_axes.stairs(y, x, baseline=None)
24862488

2487-
# Ref
2488-
ref_ax = fig_ref.add_subplot()
24892489
style = {'solid_joinstyle': 'miter', 'solid_capstyle': 'butt'}
2490-
ref_ax.plot(range(4), [5, 6, 7, 7], drawstyle='steps-post', **style)
2491-
ref_ax.set_ylim(0, None)
2490+
2491+
ref_axes = fig_ref.add_subplot()
2492+
ref_axes.plot(x, np.append(y, y[-1]), drawstyle='steps-post', **style)
24922493

24932494

24942495
def test_stairs_empty():

0 commit comments

Comments
 (0)