22
22
import matplotlib .collections as mcoll
23
23
import matplotlib .colors as mcolors
24
24
import matplotlib .docstring as docstring
25
+ import matplotlib .projections as proj
25
26
import matplotlib .scale as mscale
26
27
import matplotlib .transforms as mtransforms
27
28
from matplotlib .axes import Axes , rcParams
@@ -71,7 +72,7 @@ def __init__(
71
72
.. versionadded :: 1.2.1
72
73
*sharez*
73
74
74
- ''' % {'scale' : ' | ' .join ([ repr (x ) for x in mscale .get_scale_names ()] )}
75
+ ''' % {'scale' : ' | ' .join (repr (x ) for x in mscale .get_scale_names ())}
75
76
76
77
if rect is None :
77
78
rect = [0.0 , 0.0 , 1.0 , 1.0 ]
@@ -375,7 +376,7 @@ def set_zmargin(self, m):
375
376
.. versionadded :: 1.1.0
376
377
This function was added, but not tested. Please report any bugs.
377
378
"""
378
- if m < 0 or m > 1 :
379
+ if m < 0 or m > 1 :
379
380
raise ValueError ("margin must be in range 0 to 1" )
380
381
self ._zmargin = m
381
382
self .stale = True
@@ -493,7 +494,8 @@ def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
493
494
# data.
494
495
self .xy_dataLim .update_from_data_xy (np .array ([x , y ]).T , not had_data )
495
496
if z is not None :
496
- self .zz_dataLim .update_from_data_xy (np .array ([z , z ]).T , not had_data )
497
+ self .zz_dataLim .update_from_data_xy (
498
+ np .array ([z , z ]).T , not had_data )
497
499
498
500
# Let autoscale_view figure out how to use this data.
499
501
self .autoscale_view ()
@@ -773,19 +775,19 @@ def get_xlim3d(self):
773
775
get_xlim = get_xlim3d
774
776
if get_xlim .__doc__ is not None :
775
777
get_xlim .__doc__ += """
776
- .. versionchanged :: 1.1.0
777
- This function now correctly refers to the 3D x-limits
778
- """
778
+ .. versionchanged :: 1.1.0
779
+ This function now correctly refers to the 3D x-limits
780
+ """
779
781
780
782
def get_ylim3d (self ):
781
783
return tuple (self .xy_viewLim .intervaly )
782
784
get_ylim3d .__doc__ = maxes .Axes .get_ylim .__doc__
783
785
get_ylim = get_ylim3d
784
786
if get_ylim .__doc__ is not None :
785
787
get_ylim .__doc__ += """
786
- .. versionchanged :: 1.1.0
787
- This function now correctly refers to the 3D y-limits.
788
- """
788
+ .. versionchanged :: 1.1.0
789
+ This function now correctly refers to the 3D y-limits.
790
+ """
789
791
790
792
def get_zlim3d (self ):
791
793
'''Get 3D z limits.'''
@@ -809,10 +811,9 @@ def set_xscale(self, value, **kwargs):
809
811
self ._update_transScale ()
810
812
if maxes .Axes .set_xscale .__doc__ is not None :
811
813
set_xscale .__doc__ = maxes .Axes .set_xscale .__doc__ + """
812
-
813
- .. versionadded :: 1.1.0
814
- This function was added, but not tested. Please report any bugs.
815
- """
814
+ .. versionadded :: 1.1.0
815
+ This function was added, but not tested. Please report any bugs.
816
+ """
816
817
817
818
def set_yscale (self , value , ** kwargs ):
818
819
self .yaxis ._set_scale (value , ** kwargs )
@@ -821,10 +822,9 @@ def set_yscale(self, value, **kwargs):
821
822
self .stale = True
822
823
if maxes .Axes .set_yscale .__doc__ is not None :
823
824
set_yscale .__doc__ = maxes .Axes .set_yscale .__doc__ + """
824
-
825
- .. versionadded :: 1.1.0
826
- This function was added, but not tested. Please report any bugs.
827
- """
825
+ .. versionadded :: 1.1.0
826
+ This function was added, but not tested. Please report any bugs.
827
+ """
828
828
829
829
@docstring .dedent_interpd
830
830
def set_zscale (self , value , ** kwargs ):
@@ -1340,7 +1340,7 @@ def ticklabel_format(
1340
1340
self .xaxis .major .formatter .set_scientific (sb )
1341
1341
if axis in ['both' , 'y' ]:
1342
1342
self .yaxis .major .formatter .set_scientific (sb )
1343
- if axis in ['both' , 'z' ] :
1343
+ if axis in ['both' , 'z' ]:
1344
1344
self .zaxis .major .formatter .set_scientific (sb )
1345
1345
if scilimits is not None :
1346
1346
if axis in ['both' , 'x' ]:
@@ -1413,7 +1413,7 @@ def tick_params(self, axis='both', **kwargs):
1413
1413
This function was added, but not tested. Please report any bugs.
1414
1414
"""
1415
1415
super ().tick_params (axis , ** kwargs )
1416
- if axis in ['z' , 'both' ] :
1416
+ if axis in ['z' , 'both' ]:
1417
1417
zkw = dict (kwargs )
1418
1418
zkw .pop ('top' , None )
1419
1419
zkw .pop ('bottom' , None )
@@ -1676,8 +1676,8 @@ def get_normals(polygons):
1676
1676
v1 = np .empty ((len (polygons ), 3 ))
1677
1677
v2 = np .empty ((len (polygons ), 3 ))
1678
1678
for poly_i , ps in enumerate (polygons ):
1679
- # pick three points around the polygon at which to find the normal
1680
- # doesn't vectorize because polygons is jagged
1679
+ # pick three points around the polygon at which to find the
1680
+ # normal doesn't vectorize because polygons is jagged
1681
1681
i1 , i2 , i3 = 0 , len (ps )// 3 , 2 * len (ps )// 3
1682
1682
v1 [poly_i , :] = ps [i1 , :] - ps [i2 , :]
1683
1683
v2 [poly_i , :] = ps [i2 , :] - ps [i3 , :]
@@ -1937,7 +1937,8 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,
1937
1937
cmap = kwargs .get ('cmap' , None )
1938
1938
shade = kwargs .pop ('shade' , cmap is None )
1939
1939
1940
- tri , args , kwargs = Triangulation .get_from_args_and_kwargs (* args , ** kwargs )
1940
+ tri , args , kwargs = \
1941
+ Triangulation .get_from_args_and_kwargs (* args , ** kwargs )
1941
1942
if 'Z' in kwargs :
1942
1943
z = np .asarray (kwargs .pop ('Z' ))
1943
1944
else :
@@ -2027,7 +2028,8 @@ def _3d_extend_contour(self, cset, stride=5):
2027
2028
for col in colls :
2028
2029
self .collections .remove (col )
2029
2030
2030
- def add_contour_set (self , cset , extend3d = False , stride = 5 , zdir = 'z' , offset = None ):
2031
+ def add_contour_set (
2032
+ self , cset , extend3d = False , stride = 5 , zdir = 'z' , offset = None ):
2031
2033
zdir = '-' + zdir
2032
2034
if extend3d :
2033
2035
self ._3d_extend_contour (cset , stride )
@@ -2040,7 +2042,7 @@ def add_contour_set(self, cset, extend3d=False, stride=5, zdir='z', offset=None)
2040
2042
def add_contourf_set (self , cset , zdir = 'z' , offset = None ):
2041
2043
zdir = '-' + zdir
2042
2044
for z , linec in zip (cset .levels , cset .collections ):
2043
- if offset is not None :
2045
+ if offset is not None :
2044
2046
z = offset
2045
2047
art3d .poly_collection_2d_to_3d (linec , z , zdir = zdir )
2046
2048
linec .set_sort_zpos (z )
@@ -2225,10 +2227,8 @@ def add_collection3d(self, col, zs=0, zdir='z'):
2225
2227
- PatchCollection
2226
2228
'''
2227
2229
zvals = np .atleast_1d (zs )
2228
- if len (zvals ) > 0 :
2229
- zsortval = min (zvals )
2230
- else :
2231
- zsortval = 0 # FIXME: Fairly arbitrary. Is there a better value?
2230
+ zsortval = (np .min (zvals ) if zvals .size
2231
+ else 0 ) # FIXME: arbitrary default
2232
2232
2233
2233
# FIXME: use issubclass() (although, then a 3D collection
2234
2234
# object would also pass.) Maybe have a collection3d
@@ -2345,12 +2345,12 @@ def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
2345
2345
if 'alpha' in kwargs :
2346
2346
p .set_alpha (kwargs ['alpha' ])
2347
2347
2348
- if len (verts ) > 0 :
2348
+ if len (verts ) > 0 :
2349
2349
# the following has to be skipped if verts is empty
2350
2350
# NOTE: Bugs could still occur if len(verts) > 0,
2351
2351
# but the "2nd dimension" is empty.
2352
- xs , ys = list ( zip (* verts ) )
2353
- else :
2352
+ xs , ys = zip (* verts )
2353
+ else :
2354
2354
xs , ys = [], []
2355
2355
2356
2356
xs , ys , verts_zs = art3d .juggle_axes (xs , ys , verts_zs , zdir )
@@ -2485,7 +2485,8 @@ def quiver(self, *args,
2485
2485
length = 1 , arrow_length_ratio = .3 , pivot = 'tail' , normalize = False ,
2486
2486
** kwargs ):
2487
2487
"""
2488
- ax.quiver(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, pivot='tail', normalize=False, **kwargs)
2488
+ ax.quiver(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, \
2489
+ pivot='tail', normalize=False, **kwargs)
2489
2490
2490
2491
Plot a 3D field of arrows.
2491
2492
@@ -2549,7 +2550,8 @@ def calc_arrow(uvw, angle=15):
2549
2550
[- y * s , x * s , c ]])
2550
2551
# opposite rotation negates all the sin terms
2551
2552
Rneg = Rpos .copy ()
2552
- Rneg [[0 , 1 , 2 , 2 ], [2 , 2 , 0 , 1 ]] = - Rneg [[0 , 1 , 2 , 2 ], [2 , 2 , 0 , 1 ]]
2553
+ Rneg [[0 , 1 , 2 , 2 ], [2 , 2 , 0 , 1 ]] = \
2554
+ - Rneg [[0 , 1 , 2 , 2 ], [2 , 2 , 0 , 1 ]]
2553
2555
2554
2556
# multiply them to get the rotated vector
2555
2557
return Rpos .dot (uvw ), Rneg .dot (uvw )
@@ -2569,7 +2571,8 @@ def calc_arrow(uvw, angle=15):
2569
2571
for k in input_args ]
2570
2572
2571
2573
# extract the masks, if any
2572
- masks = [k .mask for k in input_args if isinstance (k , np .ma .MaskedArray )]
2574
+ masks = [k .mask for k in input_args
2575
+ if isinstance (k , np .ma .MaskedArray )]
2573
2576
# broadcast to match the shape
2574
2577
bcast = np .broadcast_arrays (* (input_args + masks ))
2575
2578
input_args = bcast [:argi ]
@@ -2622,9 +2625,9 @@ def calc_arrow(uvw, angle=15):
2622
2625
if len (XYZ ) > 0 :
2623
2626
# compute the shaft lines all at once with an outer product
2624
2627
shafts = (XYZ - np .multiply .outer (shaft_dt , UVW )).swapaxes (0 , 1 )
2625
- # compute head direction vectors, n heads by 2 sides by 3 dimensions
2628
+ # compute head direction vectors, n heads x 2 sides x 3 dimensions
2626
2629
head_dirs = np .array ([calc_arrow (d ) for d in UVW ])
2627
- # compute all head lines at once, starting from where the shaft ends
2630
+ # compute all head lines at once, starting from the shaft ends
2628
2631
heads = shafts [:, :1 ] - np .multiply .outer (arrow_dt , head_dirs )
2629
2632
# stack left and right head lines together
2630
2633
heads .shape = (len (arrow_dt ), - 1 , 3 )
@@ -2669,13 +2672,13 @@ def voxels(self, *args, facecolors=None, edgecolors=None, **kwargs):
2669
2672
2670
2673
x, y, z : 3D np.array, optional
2671
2674
The coordinates of the corners of the voxels. This should broadcast
2672
- to a shape one larger in every dimension than the shape of `filled`.
2673
- These can be used to plot non-cubic voxels.
2675
+ to a shape one larger in every dimension than the shape of
2676
+ `filled`. These can be used to plot non-cubic voxels.
2674
2677
2675
2678
If not specified, defaults to increasing integers along each axis,
2676
2679
like those returned by :func:`~numpy.indices`.
2677
- As indicated by the ``/`` in the function signature, these arguments
2678
- can only be passed positionally.
2680
+ As indicated by the ``/`` in the function signature, these
2681
+ arguments can only be passed positionally.
2679
2682
2680
2683
facecolors, edgecolors : array_like, optional
2681
2684
The color to draw the faces and edges of the voxels. Can only be
@@ -2758,7 +2761,7 @@ def _broadcast_color_arg(color, name):
2758
2761
# broadcast but no default on edgecolors
2759
2762
edgecolors = _broadcast_color_arg (edgecolors , 'edgecolors' )
2760
2763
2761
- # always scale to the full array, even if the data is only in the center
2764
+ # scale to the full array, even if the data is only in the center
2762
2765
self .auto_scale_xyz (x , y , z )
2763
2766
2764
2767
# points lying on corners of a square
@@ -2778,8 +2781,8 @@ def permutation_matrices(n):
2778
2781
yield mat
2779
2782
mat = np .roll (mat , 1 , axis = 0 )
2780
2783
2781
- # iterate over each of the YZ, ZX, and XY orientations, finding faces to
2782
- # render
2784
+ # iterate over each of the YZ, ZX, and XY orientations, finding faces
2785
+ # to render
2783
2786
for permute in permutation_matrices (3 ):
2784
2787
# find the set of ranges to iterate over
2785
2788
pc , qc , rc = permute .T .dot (size )
@@ -2822,7 +2825,8 @@ def permutation_matrices(n):
2822
2825
if filled [ik ]:
2823
2826
voxel_faces [ik ].append (pk2 + square_rot )
2824
2827
2825
- # iterate over the faces, and generate a Poly3DCollection for each voxel
2828
+ # iterate over the faces, and generate a Poly3DCollection for each
2829
+ # voxel
2826
2830
polygons = {}
2827
2831
for coord , faces_inds in voxel_faces .items ():
2828
2832
# convert indices into 3D positions
@@ -2871,5 +2875,4 @@ def get_test_data(delta=0.05):
2871
2875
# Register Axes3D as a 'projection' object available
2872
2876
# for use just like any other axes
2873
2877
########################################################
2874
- import matplotlib .projections as proj
2875
2878
proj .projection_registry .register (Axes3D )
0 commit comments