8000 Ensure that arguments to quiver() are not matrices. · matplotlib/matplotlib@80bf85b · GitHub
[go: up one dir, main page]

Skip to content

Commit 80bf85b

Browse files
committed
Ensure that arguments to quiver() are not matrices.
1 parent 354a430 commit 80bf85b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,3 +2178,13 @@ def _check_and_log_subprocess(command, logger, **kwargs):
21782178
.format(command, exc.output.decode('utf-8')))
21792179
logger.debug(report)
21802180
return report
2181+
2182+
2183+
def _check_not_matrix(**kwargs):
2184+
"""
2185+
If any value in *kwargs* is a `np.matrix`, raise a TypeError with the key
2186+
name in its message.
2187+
"""
2188+
for k, v in kwargs.items():
2189+
if isinstance(v, np.matrix):
2190+
raise TypeError(f"Argument {k!r} cannot be a np.matrix")

lib/matplotlib/quiver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def contains(self, mouseevent):
381381
# arguments for doing colored vector plots. Pulling it out here
382382
# allows both Quiver and Barbs to use it
383383
def _parse_args(*args):
384-
X, Y, U, V, C = [None] * 5
384+
X = Y = U = V = C = None
385385
args = list(args)
386386

387387
# The use of atleast_1d allows for handling scalar arguments while also
@@ -390,6 +390,7 @@ def _parse_args(*args):
390390
C = np.atleast_1d(args.pop(-1))
391391
V = np.atleast_1d(args.pop(-1))
392392
U = np.atleast_1d(args.pop(-1))
393+
cbook._check_not_matrix(U=U, V=V, C=C)
393394
if U.ndim == 1:
394395
nr, nc = 1, U.shape[0]
395396
else:

tutorials/introductory/usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@
137137
# For example, to convert a `pandas.DataFrame` ::
138138
#
139139
# a = pandas.DataFrame(np.random.rand(4,5), columns = list('abcde'))
140-
# a_asndarray = a.values
140+
# a_asarray = a.values
141141
#
142-
# and to covert a `np.matrix` ::
142+
# and to convert a `np.matrix` ::
143143
#
144144
# b = np.matrix([[1,2],[3,4]])
145145
# b_asarray = np.asarray(b)

0 commit comments

Comments
 (0)
0