Skip to content

fix: keep baseline scale to baseline 0 even if set to None #18663

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
merged 2 commits into from
Oct 12, 2020
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
2 changes: 2 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down