2222import matplotlib .collections as mcoll
2323import matplotlib .colors as mcolors
2424import matplotlib .docstring as docstring
25+ import matplotlib .projections as proj
2526import matplotlib .scale as mscale
2627import matplotlib .transforms as mtransforms
2728from matplotlib .axes import Axes , rcParams
@@ -71,7 +72,7 @@ def __init__(
7172 .. versionadded :: 1.2.1
7273 *sharez*
7374
74- ''' % {'scale' : ' | ' .join ([ repr (x ) for x in mscale .get_scale_names ()] )}
75+ ''' % {'scale' : ' | ' .join (repr (x ) for x in mscale .get_scale_names ())}
7576
7677 if rect is None :
7778 rect = [0.0 , 0.0 , 1.0 , 1.0 ]
@@ -375,7 +376,7 @@ def set_zmargin(self, m):
375376 .. versionadded :: 1.1.0
376377 This function was added, but not tested. Please report any bugs.
377378 """
378- if m < 0 or m > 1 :
379+ if m < 0 or m > 1 :
379380 raise ValueError ("margin must be in range 0 to 1" )
380381 self ._zmargin = m
381382 self .stale = True
@@ -493,7 +494,8 @@ def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
493494 # data.
494495 self .xy_dataLim .update_from_data_xy (np .array ([x , y ]).T , not had_data )
495496 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 )
497499
498500 # Let autoscale_view figure out how to use this data.
499501 self .autoscale_view ()
@@ -773,19 +775,19 @@ def get_xlim3d(self):
773775 get_xlim = get_xlim3d
774776 if get_xlim .__doc__ is not None :
775777 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+ """
779781
780782 def get_ylim3d (self ):
781783 return tuple (self .xy_viewLim .intervaly )
782784 get_ylim3d .__doc__ = maxes .Axes .get_ylim .__doc__
783785 get_ylim = get_ylim3d
784786 if get_ylim .__doc__ is not None :
785787 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+ """
789791
790792 def get_zlim3d (self ):
791793 '''Get 3D z limits.'''
@@ -809,10 +811,9 @@ def set_xscale(self, value, **kwargs):
809811 self ._update_transScale ()
810812 if maxes .Axes .set_xscale .__doc__ is not None :
811813 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+ """
816817
817818 def set_yscale (self , value , ** kwargs ):
818819 self .yaxis ._set_scale (value , ** kwargs )
@@ -821,10 +822,9 @@ def set_yscale(self, value, **kwargs):
821822 self .stale = True
822823 if maxes .Axes .set_yscale .__doc__ is not None :
823824 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+ """
828828
829829 @docstring .dedent_interpd
830830 def set_zscale (self , value , ** kwargs ):
@@ -1340,7 +1340,7 @@ def ticklabel_format(
13401340 self .xaxis .major .formatter .set_scientific (sb )
13411341 if axis in ['both' , 'y' ]:
13421342 self .yaxis .major .formatter .set_scientific (sb )
1343- if axis in ['both' , 'z' ] :
1343+ if axis in ['both' , 'z' ]:
13441344 self .zaxis .major .formatter .set_scientific (sb )
13451345 if scilimits is not None :
13461346 if axis in ['both' , 'x' ]:
@@ -1413,7 +1413,7 @@ def tick_params(self, axis='both', **kwargs):
14131413 This function was added, but not tested. Please report any bugs.
14141414 """
14151415 super ().tick_params (axis , ** kwargs )
1416- if axis in ['z' , 'both' ] :
1416+ if axis in ['z' , 'both' ]:
14171417 zkw = dict (kwargs )
14181418 zkw .pop ('top' , None )
14191419 zkw .pop ('bottom' , None )
@@ -1676,8 +1676,8 @@ def get_normals(polygons):
16761676 v1 = np .empty ((len (polygons ), 3 ))
16771677 v2 = np .empty ((len (polygons ), 3 ))
16781678 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
16811681 i1 , i2 , i3 = 0 , len (ps )// 3 , 2 * len (ps )// 3
16821682 v1 [poly_i , :] = ps [i1 , :] - ps [i2 , :]
16831683 v2 [poly_i , :] = ps [i2 , :] - ps [i3 , :]
@@ -1937,7 +1937,8 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,
19371937 cmap = kwargs .get ('cmap' , None )
19381938 shade = kwargs .pop ('shade' , cmap is None )
19391939
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 )
19411942 if 'Z' in kwargs :
19421943 z = np .asarray (kwargs .pop ('Z' ))
19431944 else :
@@ -2027,7 +2028,8 @@ def _3d_extend_contour(self, cset, stride=5):
20272028 for col in colls :
20282029 self .collections .remove (col )
20292030
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 ):
20312033 zdir = '-' + zdir
20322034 if extend3d :
20332035 self ._3d_extend_contour (cset , stride )
@@ -2040,7 +2042,7 @@ def add_contour_set(self, cset, extend3d=False, stride=5, zdir='z', offset=None)
20402042 def add_contourf_set (self , cset , zdir = 'z' , offset = None ):
20412043 zdir = '-' + zdir
20422044 for z , linec in zip (cset .levels , cset .collections ):
2043- if offset is not None :
2045+ if offset is not None :
20442046 z = offset
20452047 art3d .poly_collection_2d_to_3d (linec , z , zdir = zdir )
20462048 linec .set_sort_zpos (z )
@@ -2225,10 +2227,8 @@ def add_collection3d(self, col, zs=0, zdir='z'):
22252227 - PatchCollection
22262228 '''
22272229 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
22322232
22332233 # FIXME: use issubclass() (although, then a 3D collection
22342234 # object would also pass.) Maybe have a collection3d
@@ -2345,12 +2345,12 @@ def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
23452345 if 'alpha' in kwargs :
23462346 p .set_alpha (kwargs ['alpha' ])
23472347
2348- if len (verts ) > 0 :
2348+ if len (verts ) > 0 :
23492349 # the following has to be skipped if verts is empty
23502350 # NOTE: Bugs could still occur if len(verts) > 0,
23512351 # but the "2nd dimension" is empty.
2352- xs , ys = list ( zip (* verts ) )
2353- else :
2352+ xs , ys = zip (* verts )
2353+ else :
23542354 xs , ys = [], []
23552355
23562356 xs , ys , verts_zs = art3d .juggle_axes (xs , ys , verts_zs , zdir )
@@ -2485,7 +2485,8 @@ def quiver(self, *args,
24852485 length = 1 , arrow_length_ratio = .3 , pivot = 'tail' , normalize = False ,
24862486 ** kwargs ):
24872487 """
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)
24892490
24902491 Plot a 3D field of arrows.
24912492
@@ -2549,7 +2550,8 @@ def calc_arrow(uvw, angle=15):
25492550 [- y * s , x * s , c ]])
25502551 # opposite rotation negates all the sin terms
25512552 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 ]]
25532555
25542556 # multiply them to get the rotated vector
25552557 return Rpos .dot (uvw ), Rneg .dot (uvw )
@@ -2569,7 +2571,8 @@ def calc_arrow(uvw, angle=15):
25692571 for k in input_args ]
25702572
25712573 # 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 )]
25732576 # broadcast to match the shape
25742577 bcast = np .broadcast_arrays (* (input_args + masks ))
25752578 input_args = bcast [:argi ]
@@ -2622,9 +2625,9 @@ def calc_arrow(uvw, angle=15):
26222625 if len (XYZ ) > 0 :
26232626 # compute the shaft lines all at once with an outer product
26242627 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
26262629 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
26282631 heads = shafts [:, :1 ] - np .multiply .outer (arrow_dt , head_dirs )
26292632 # stack left and right head lines together
26302633 heads .shape = (len (arrow_dt ), - 1 , 3 )
@@ -2669,13 +2672,13 @@ def voxels(self, *args, facecolors=None, edgecolors=None, **kwargs):
26692672
26702673 x, y, z : 3D np.array, optional
26712674 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.
26742677
26752678 If not specified, defaults to increasing integers along each axis,
26762679 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.
26792682
26802683 facecolors, edgecolors : array_like, optional
26812684 The color to draw the faces and edges of the voxels. Can only be
@@ -2758,7 +2761,7 @@ def _broadcast_color_arg(color, name):
27582761 # broadcast but no default on edgecolors
27592762 edgecolors = _broadcast_color_arg (edgecolors , 'edgecolors' )
27602763
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
27622765 self .auto_scale_xyz (x , y , z )
27632766
27642767 # points lying on corners of a square
@@ -2778,8 +2781,8 @@ def permutation_matrices(n):
27782781 yield mat
27792782 mat = np .roll (mat , 1 , axis = 0 )
27802783
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
27832786 for permute in permutation_matrices (3 ):
27842787 # find the set of ranges to iterate over
27852788 pc , qc , rc = permute .T .dot (size )
@@ -2822,7 +2825,8 @@ def permutation_matrices(n):
28222825 if filled [ik ]:
28232826 voxel_faces [ik ].append (pk2 + square_rot )
28242827
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
28262830 polygons = {}
28272831 for coord , faces_inds in voxel_faces .items ():
28282832 # convert indices into 3D positions
@@ -2871,5 +2875,4 @@ def get_test_data(delta=0.05):
28712875# Register Axes3D as a 'projection' object available
28722876# for use just like any other axes
28732877########################################################
2874- import matplotlib .projections as proj
28752878proj .projection_registry .register (Axes3D )
0 commit comments