Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 348d672

Browse filesBrowse files
committed
Support empty stairs.
1 parent cdb6b51 commit 348d672
Copy full SHA for 348d672

File tree

Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+2-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.