diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index f9d7290fc6be..9d5fe3001624 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6793,8 +6793,10 @@ def stairs(self, values, edges=None, *, baseline = 0 if orientation == 'vertical': patch.sticky_edges.y.append(np.min(baseline)) + self.update_datalim([(edges[0], np.min(baseline))]) else: patch.sticky_edges.x.append(np.min(baseline)) + self.update_datalim([(np.min(baseline), edges[0])]) self._request_autoscale_view() return patch diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 336543329355..6d3050c3df8e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1908,6 +1908,19 @@ def test_stairs_update(fig_test, fig_ref): ref_ax.set_ylim(ylim) +@check_figures_equal(extensions=['png']) +def test_stairs_baseline_0(fig_test, fig_ref): + # Test + test_ax = fig_test.add_subplot() + test_ax.stairs([5, 6, 7], baseline=None) + + # Ref + ref_ax = fig_ref.add_subplot() + style = {'solid_joinstyle': 'miter', 'solid_capstyle': 'butt'} + ref_ax.plot(range(4), [5, 6, 7, 7], drawstyle='steps-post', **style) + ref_ax.set_ylim(0, None) + + def test_stairs_invalid_nan(): with pytest.raises(ValueError, match='Nan values in "edges"'): plt.stairs([1, 2], [0, np.nan, 1])