Skip to content

Commit ad389f6

Browse files
committed
Consistent handling of *args in Axes.stem
1 parent e9bd13a commit ad389f6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Consistent handling of \*args in Axes.stem
2+
------------------------------------------
3+
4+
:meth:`matplotlib.axex.Axes.stem` now raises TypeError when passed
5+
unhandled positional arguments. If two or more arguments are passed
6+
(ie X, Y, [linefmt], ...) and Y cannot be cast to an array, an error
7+
will be raised instead of treating X as Y and Y as linefmt.

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,17 +2350,19 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
23502350
which inspired this method.
23512351
23522352
"""
2353-
# Assume there's at least one data array
2353+
if not 1 <= len(args) <= 5:
2354+
raise TypeError('stem expected between 1 and 5 positional '
2355+
'arguments, got {}'.format(args))
2356+
23542357
y = np.asarray(args[0])
23552358
args = args[1:]
23562359

23572360
# Try a second one
2358-
try:
2359-
x, y = y, np.asarray(args[0], dtype=float)
2360-
except (IndexError, ValueError):
2361-
# The second array doesn't make sense, or it doesn't exist
2361+
if not args:
23622362
x = np.arange(len(y))
23632363
else:
2364+
x = y
2365+
y = np.asarray(args[0], dtype=float)
23642366
args = args[1:]
23652367

23662368
# defaults for formats

0 commit comments

Comments
 (0)