1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
From 8f0792cb9c8d80ff17d1f8f0500897f0e56e8fea Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Sun, 1 Jan 2023 14:55:41 +0100
Subject: [PATCH] Fix argument checking in Axes3D.quiver
---
lib/mpl_toolkits/mplot3d/axes3d.py | 45 ++++++++++++------------------
1 file changed, 18 insertions(+), 27 deletions(-)
--- a/lib/mpl_toolkits/mplot3d/axes3d.py
+++ b/lib/mpl_toolkits/mplot3d/axes3d.py
@@ -1377,7 +1377,7 @@ class Axes3D(Axes):
The lightsource to use when *shade* is True.
**kwargs
- Other arguments are forwarded to `.Poly3DCollection`.
+ Other keyword arguments are forwarded to `.Poly3DCollection`.
"""
had_data = self.has_data()
@@ -1625,7 +1625,7 @@ class Axes3D(Axes):
of the new default of ``rcount = ccount = 50``.
**kwargs
- Other arguments are forwarded to `.Line3DCollection`.
+ Other keyword arguments are forwarded to `.Line3DCollection`.
"""
had_data = self.has_data()
@@ -1752,7 +1752,7 @@ class Axes3D(Axes):
lightsource : `~matplotlib.colors.LightSource`
The lightsource to use when *shade* is True.
**kwargs
- All other arguments are passed on to
+ All other keyword arguments are passed on to
:class:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`
Examples
@@ -2161,7 +2161,7 @@ class Axes3D(Axes):
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER
**kwargs
- All other arguments are passed on to `~.axes.Axes.scatter`.
+ All other keyword arguments are passed on to `~.axes.Axes.scatter`.
Returns
-------
@@ -2213,7 +2213,8 @@ class Axes3D(Axes):
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER
**kwargs
- Other arguments are forwarded to `matplotlib.axes.Axes.bar`.
+ Other keyword arguments are forwarded to
+ `matplotlib.axes.Axes.bar`.
Returns
-------
@@ -2421,19 +2422,16 @@ class Axes3D(Axes):
return ret
@_preprocess_data()
- def quiver(self, *args,
+ def quiver(self, X, Y, Z, U, V, W, *,
length=1, arrow_length_ratio=.3, pivot='tail', normalize=False,
**kwargs):
"""
- ax.quiver(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, \
-pivot='tail', normalize=False, **kwargs)
-
Plot a 3D field of arrows.
- The arguments could be array-like or scalars, so long as they
- they can be broadcast together. The arguments can also be
- masked arrays. If an element in any of argument is masked, then
- that corresponding quiver element will not be plotted.
+ The arguments can be array-like or scalars, so long as they can be
+ broadcast together. The arguments can also be masked arrays. If an
+ element in any of argument is masked, then that corresponding quiver
+ element will not be plotted.
Parameters
----------
@@ -2463,7 +2461,7 @@ pivot='tail', normalize=False, **kwargs)
**kwargs
Any additional keyword arguments are delegated to
- :class:`~matplotlib.collections.LineCollection`
+ :class:`.Line3DCollection`
"""
def calc_arrows(UVW, angle=15):
@@ -2494,22 +2492,15 @@ pivot='tail', normalize=False, **kwargs)
had_data = self.has_data()
- # handle args
- argi = 6
- if len(args) < argi:
- raise ValueError('Wrong number of arguments. Expected %d got %d' %
- (argi, len(args)))
-
- # first 6 arguments are X, Y, Z, U, V, W
- input_args = args[:argi]
+ input_args = [X, Y, Z, U, V, W]
# extract the masks, if any
masks = [k.mask for k in input_args
if isinstance(k, np.ma.MaskedArray)]
# broadcast to match the shape
bcast = np.broadcast_arrays(*input_args, *masks)
- input_args = bcast[:argi]
- masks = bcast[argi:]
+ input_args = bcast[:6]
+ masks = bcast[6:]
if masks:
# combine the masks into one
mask = functools.reduce(np.logical_or, masks)
@@ -2521,7 +2512,7 @@ pivot='tail', normalize=False, **kwargs)
if any(len(v) == 0 for v in input_args):
# No quivers, so just make an empty collection and return early
- linec = art3d.Line3DCollection([], *args[argi:], **kwargs)
+ linec = art3d.Line3DCollection([], **kwargs)
self.add_collection(linec)
return linec
@@ -2535,7 +2526,7 @@ pivot='tail', normalize=False, **kwargs)
shaft_dt -= length / 2
XYZ = np.column_stack(input_args[:3])
- UVW = np.column_stack(input_args[3:argi]).astype(float)
+ UVW = np.column_stack(input_args[3:]).astype(float)
# Normalize rows of UVW
norm = np.linalg.norm(UVW, axis=1)
@@ -2564,7 +2555,7 @@ pivot='tail', normalize=False, **kwargs)
else:
lines = []
- linec = art3d.Line3DCollection(lines, *args[argi:], **kwargs)
+ linec = art3d.Line3DCollection(lines, **kwargs)
self.add_collection(linec)
self.auto_scale_xyz(XYZ[:, 0], XYZ[:, 1], XYZ[:, 2], had_data)
|