Skip to content

Commit 7572823

Browse files
committed
Check that stem input is 1D
This also has the side-effect of casting torch Tensors to NumPy arrays, which fixes matplotlib#30216. Since `stem` is made up of `plot` and `[hv]lines` whic already do this cast, this just moves it up one level which prevents doing it twice.
1 parent ede1ebb commit 7572823

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,6 +3436,9 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
34363436
else: # horizontal
34373437
heads, locs = self._process_unit_info([("x", heads), ("y", locs)])
34383438

3439+
heads = cbook._check_1d(heads)
3440+
locs = cbook._check_1d(locs)
3441+
34393442
# resolve line format
34403443
if linefmt is None:
34413444
linefmt = args[0] if len(args) > 0 else "C0-"

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4744,6 +4744,11 @@ def _assert_equal(stem_container, expected):
47444744
_assert_equal(ax.stem(y, linefmt='r--'), expected=([0, 1, 2], y))
47454745
_assert_equal(ax.stem(y, 'r--'), expected=([0, 1, 2], y))
47464746

4747+
with pytest.raises(ValueError):
4748+
ax.stem([[y]])
4749+
with pytest.raises(ValueError):
4750+
ax.stem([[x]], y)
4751+
47474752

47484753
def test_stem_markerfmt():
47494754
"""Test that stem(..., markerfmt=...) produces the intended markers."""

0 commit comments

Comments
 (0)