Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adf3784

Browse files
committed
Consistent handling fo *args in Axes.stem
1 parent 31d2c2f commit adf3784

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,18 +2350,20 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
23502350
which inspired this method.
23512351
23522352
"""
2353+
if len(args) > 5:
2354+
raise TypeError('Too many positional arguments')
2355+
23532356
# Assume there's at least one data array
23542357
y = np.asarray(args[0])
23552358
args = args[1:]
23562359

23572360
# Try a second one
23582361
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
2362+
x, *args = args
2363+
except IndexError:
23622364
x = np.arange(len(y))
23632365
else:
2364-
args = args[1:]
2366+
x, y = y, np.asarray(x, dtype=float)
23652367

23662368
# defaults for formats
23672369
if linefmt is None:

0 commit comments

Comments
 (0)