Skip to content

Commit a2b924c

Browse files
authored
Merge pull request #19426 from anntzer/es
MNT: Support empty stairs.
2 parents 5f2b890 + 348d672 commit a2b924c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/matplotlib/patches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,8 @@ def _update_path(self):
988988
"Expected `len(values) + 1 == len(edges)`, but "
989989
f"`len(values) = {self._values.size}` and "
990990
f"`len(edges) = {self._edges.size}`.")
991-
verts, codes = [], []
991+
# Initializing with empty arrays allows supporting empty stairs.
992+
verts, codes = [np.empty((0, 2))], [np.empty(0, dtype=Path.code_type)]
992993

993994
_nan_mask = np.isnan(self._values)
994995
if self._baseline is not None:

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,13 @@ def test_stairs_baseline_0(fig_test, fig_ref):
19321932
ref_ax.set_ylim(0, None)
19331933

19341934

1935+
def test_stairs_empty():
1936+
ax = plt.figure().add_subplot()
1937+
ax.stairs([], [42])
1938+
assert ax.get_xlim() == (39, 45)
1939+
assert ax.get_ylim() == (-0.06, 0.06)
1940+
1941+
19351942
def test_stairs_invalid_nan():
19361943
with pytest.raises(ValueError, match='Nan values in "edges"'):
19371944
plt.stairs([1, 2], [0, np.nan, 1])

0 commit comments

Comments
 (0)