34
34
from . import art3d
35
35
from . import proj3d
36
36
from . import axis3d
37
- from mpl_toolkits .mplot3d .art3d import Line3DCollection
38
37
39
38
def unit_bbox ():
40
39
box = Bbox (np .array ([[0 , 0 ], [1 , 1 ]]))
@@ -2431,19 +2430,23 @@ def quiver(self, *args, **kwargs):
2431
2430
*U*, *V*, *W*:
2432
2431
The direction vector that the arrow is pointing
2433
2432
2434
- The arguments could be iterable or scalars they will be broadcast together. The arguments can
2435
- also be masked arrays, if a position in any of argument is masked, then the corresponding
2436
- quiver will not be plotted.
2433
+ The arguments could be array-like or scalars, so long as they
2434
+ they can be broadcast together. The arguments can also be
2435
+ masked arrays. If an element in any of argument is masked, then
2436
+ that corresponding quiver element will not be plotted.
2437
2437
2438
2438
Keyword arguments:
2439
2439
2440
2440
*length*: [1.0 | float]
2441
- The length of each quiver, default to 1.0, the unit is the same with the axes
2441
+ The length of each quiver, default to 1.0, the unit is
2442
+ the same with the axes
2442
2443
2443
2444
*arrow_length_ratio*: [0.3 | float]
2444
- The ratio of the arrow head with respect to the quiver, default to 0.3
2445
+ The ratio of the arrow head with respect to the quiver,
2446
+ default to 0.3
2445
2447
2446
- Any additional keyword arguments are delegated to :class:`~matplotlib.collections.LineCollection`
2448
+ Any additional keyword arguments are delegated to
2449
+ :class:`~matplotlib.collections.LineCollection`
2447
2450
2448
2451
"""
2449
2452
def calc_arrow (u , v , w , angle = 15 ):
@@ -2472,8 +2475,8 @@ def rotatefunction(angle):
2472
2475
2473
2476
# construct the rotation matrix
2474
2477
R = np .matrix ([[c + (x ** 2 )* (1 - c ), x * y * (1 - c )- z * s , x * z * (1 - c )+ y * s ],
2475
- [y * x * (1 - c )+ z * s , c + (y ** 2 )* (1 - c ), y * z * (1 - c )- x * s ],
2476
- [z * x * (1 - c )- y * s , z * y * (1 - c )+ x * s , c + (z ** 2 )* (1 - c )]])
2478
+ [y * x * (1 - c )+ z * s , c + (y ** 2 )* (1 - c ), y * z * (1 - c )- x * s ],
2479
+ [z * x * (1 - c )- y * s , z * y * (1 - c )+ x * s , c + (z ** 2 )* (1 - c )]])
2477
2480
2478
2481
# construct the column vector for (u,v,w)
2479
2482
line = np .matrix ([[u ],[v ],[w ]])
@@ -2512,7 +2515,9 @@ def point_vector_to_line(point, vector, length):
2512
2515
# first 6 arguments are X, Y, Z, U, V, W
2513
2516
input_args = args [:argi ]
2514
2517
# if any of the args are scalar, convert into list
2515
- input_args = [[k ] if isinstance (k , (int , float )) else k for k in input_args ]
2518
+ input_args = [[k ] if isinstance (k , (int , float )) else k
2519
+ for k in input_args ]
2520
+
2516
2521
# extract the masks, if any
2517
2522
masks = [k .mask for k in input_args if isinstance (k , np .ma .MaskedArray )]
2518
2523
# broadcast to match the shape
@@ -2523,36 +2528,43 @@ def point_vector_to_line(point, vector, length):
2523
2528
# combine the masks into one
2524
2529
mask = reduce (np .logical_or , masks )
2525
2530
# put mask on and compress
2526
- input_args = [np .ma .array (k , mask = mask ).compressed () for k in input_args ]
2531
+ input_args = [np .ma .array (k , mask = mask ).compressed ()
2532
+ for k in input_args ]
2527
2533
else :
2528
2534
input_args = [k .flatten () for k in input_args ]
2529
2535
2536
+ if any (len (v ) == 0 for v in input_args ):
2537
+ # No quivers, so just make an empty collection and return early
2538
+ linec = art3d .Line3DCollection ([], * args [6 :], ** kwargs )
2539
+ self .add_collection (linec )
2540
+ return linec
2541
+
2530
2542
points = input_args [:3 ]
2531
2543
vectors = input_args [3 :]
2532
2544
2533
2545
# Below assertions must be true before proceed
2534
2546
# must all be ndarray
2535
- assert all ([ isinstance (k , np .ndarray ) for k in input_args ] )
2547
+ assert all (isinstance (k , np .ndarray ) for k in input_args )
2536
2548
# must all in same shape
2537
2549
assert len (set ([k .shape for k in input_args ])) == 1
2538
2550
2539
-
2540
2551
# X, Y, Z, U, V, W
2541
- coords = list (map (lambda k : np .array (k ) if not isinstance (k , np .ndarray ) else k , args ))
2552
+ coords = (np .array (k ) if not isinstance (k , np .ndarray ) else k
2553
+ for k in args )
2542
2554
coords = [k .flatten () for k in coords ]
2543
2555
xs , ys , zs , us , vs , ws = coords
2544
2556
lines = []
2545
2557
2546
2558
# for each arrow
2547
- for i in xrange (xs .shape [0 ]):
2559
+ for i in range (xs .shape [0 ]):
2548
2560
# calulate body
2549
2561
x = xs [i ]
2550
2562
y = ys [i ]
2551
2563
z = zs [i ]
2552
2564
u = us [i ]
2553
2565
v = vs [i ]
2554
2566
w = ws [i ]
2555
- if any ([ k is np .ma .masked for k in [x , y , z , u , v , w ] ]):
2567
+ if any (k is np .ma .masked for k in [x , y , z , u , v , w ]):
2556
2568
continue
2557
2569
2558
2570
# (u,v,w) expected to be normalized, recursive to fix A=0 scenario.
@@ -2590,7 +2602,7 @@ def point_vector_to_line(point, vector, length):
2590
2602
line = list (zip (la2x , la2y , la2z ))
2591
2603
lines .append (line )
2592
2604
2593
- linec = Line3DCollection (lines , * args [6 :], ** kwargs )
2605
+ linec = art3d . Line3DCollection (lines , * args [6 :], ** kwargs )
2594
2606
self .add_collection (linec )
2595
2607
2596
2608
self .auto_scale_xyz (xs , ys , zs , had_data )
0 commit comments