17
17
18
18
import warnings
19
19
20
+ import numpy as np
20
21
import matplotlib .axes as maxes
21
22
from matplotlib .axes import Axes , rcParams
22
23
from matplotlib import cbook
26
27
from matplotlib import docstring
27
28
import matplotlib .scale as mscale
28
29
from matplotlib .tri .triangulation import Triangulation
29
- import numpy as np
30
30
from matplotlib import colors as mcolors
31
31
from matplotlib .colors import Normalize , LightSource
32
32
33
33
from . import art3d
34
34
from . import proj3d
35
35
from . import axis3d
36
36
37
+
37
38
def unit_bbox ():
38
39
box = Bbox (np .array ([[0 , 0 ], [1 , 1 ]]))
39
40
return box
40
41
42
+
41
43
class Axes3D (Axes ):
42
44
"""
43
45
3D axes object.
@@ -302,7 +304,7 @@ def get_axis_position(self):
302
304
def update_datalim (self , xys , ** kwargs ):
303
305
pass
304
306
305
- def get_autoscale_on (self ) :
307
+ def get_autoscale_on (self ):
306
308
"""
307
309
Get whether autoscaling is applied for all axes on plot commands
308
310
@@ -311,7 +313,7 @@ def get_autoscale_on(self) :
311
313
"""
312
314
return Axes .get_autoscale_on (self ) and self .get_autoscalez_on ()
313
315
314
- def get_autoscalez_on (self ) :
316
+ def get_autoscalez_on (self ):
315
317
"""
316
318
Get whether autoscaling for the z-axis is applied on plot commands
317
319
@@ -320,7 +322,7 @@ def get_autoscalez_on(self) :
320
322
"""
321
323
return self ._autoscaleZon
322
324
323
- def set_autoscale_on (self , b ) :
325
+ def set_autoscale_on (self , b ):
324
326
"""
325
327
Set whether autoscaling is applied on plot commands
326
328
@@ -332,7 +334,7 @@ def set_autoscale_on(self, b) :
332
334
Axes .set_autoscale_on (self , b )
333
335
self .set_autoscalez_on (b )
334
336
335
- def set_autoscalez_on (self , b ) :
337
+ def set_autoscalez_on (self , b ):
336
338
"""
337
339
Set whether autoscaling for the z-axis is applied on plot commands
338
340
@@ -341,9 +343,9 @@ def set_autoscalez_on(self, b) :
341
343
.. versionadded :: 1.1.0
342
344
This function was added, but not tested. Please report any bugs.
343
345
"""
344
- self ._autoscalez_on = b
346
+ self ._autoscaleZon = b
345
347
346
- def set_zmargin (self , m ) :
348
+ def set_zmargin (self , m ):
347
349
"""
348
350
Set padding of Z data limits prior to autoscaling.
349
351
@@ -360,7 +362,7 @@ def set_zmargin(self, m) :
360
362
self ._zmargin = m
361
363
self .stale = True
362
364
363
- def margins (self , * args , ** kw ) :
365
+ def margins (self , * args , ** kw ):
364
366
"""
365
367
Convenience method to set or retrieve autoscaling margins.
366
368
@@ -403,30 +405,36 @@ def margins(self, *args, **kw) :
403
405
mx = kw .pop ('x' , None )
404
406
my = kw .pop ('y' , None )
405
407
mz = kw .pop ('z' , None )
406
- if len (args ) == 1 :
408
+ if not args :
409
+ pass
410
+ elif len (args ) == 1 :
407
411
mx = my = mz = args [0 ]
408
412
elif len (args ) == 2 :
409
- # Maybe put out a warning because mz is not set?
413
+ warnings .warn (
414
+ "Passing exactly two positional arguments to Axes3D.margins "
415
+ "is deprecated. If needed, pass them as keyword arguments "
416
+ "instead" , cbook .mplDeprecation )
410
417
mx , my = args
411
418
elif len (args ) == 3 :
412
419
mx , my , mz = args
413
420
else :
414
- raise ValueError ("more than three arguments were supplied" )
421
+ raise ValueError (
422
+ "Axes3D.margins takes at most three positional arguments" )
415
423
if mx is not None :
416
424
self .set_xmargin (mx )
417
425
if my is not None :
418
426
self .set_ymargin (my )
419
427
if mz is not None :
420
428
self .set_zmargin (mz )
421
429
422
- scalex = ( mx is not None )
423
- scaley = ( my is not None )
424
- scalez = ( mz is not None )
430
+ scalex = mx is not None
431
+ scaley = my is not None
432
+ scalez = mz is not None
425
433
426
434
self .autoscale_view (tight = tight , scalex = scalex , scaley = scaley ,
427
435
scalez = scalez )
428
436
429
- def autoscale (self , enable = True , axis = 'both' , tight = None ) :
437
+ def autoscale (self , enable = True , axis = 'both' , tight = None ):
430
438
"""
431
439
Convenience method for simple axis view autoscaling.
432
440
See :meth:`matplotlib.axes.Axes.autoscale` for full explanation.
@@ -442,18 +450,18 @@ def autoscale(self, enable=True, axis='both', tight=None) :
442
450
scaley = True
443
451
scalez = True
444
452
else :
445
- scalex = False
446
- scaley = False
447
- scalez = False
448
453
if axis in ['x' , 'both' ]:
449
- self ._autoscaleXon = bool (enable )
450
- scalex = self ._autoscaleXon
454
+ self ._autoscaleXon = scalex = bool (enable )
455
+ else :
456
+ scalex = False
451
457
if axis in ['y' , 'both' ]:
452
- self ._autoscaleYon = bool (enable )
453
- scaley = self ._autoscaleYon
458
+ self ._autoscaleYon = scaley = bool (enable )
459
+ else :
460
+ scaley = False
454
461
if axis in ['z' , 'both' ]:
455
- self ._autoscaleZon = bool (enable )
456
- scalez = self ._autoscaleZon
462
+ self ._autoscaleZon = scalez = bool (enable )
463
+ else :
464
+ scalez = False
457
465
self .autoscale_view (tight = tight , scalex = scalex , scaley = scaley ,
458
466
scalez = scalez )
459
467
@@ -477,7 +485,7 @@ def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
477
485
self .autoscale_view ()
478
486
479
487
def autoscale_view (self , tight = None , scalex = True , scaley = True ,
480
- scalez = True ) :
488
+ scalez = True ):
481
489
"""
482
490
Autoscale the view limits using the data limits.
483
491
See :meth:`matplotlib.axes.Axes.autoscale_view` for documentation.
@@ -631,7 +639,6 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
631
639
return left , right
632
640
set_xlim = set_xlim3d
633
641
634
-
635
642
def set_ylim3d (self , bottom = None , top = None , emit = True , auto = False , ** kw ):
636
643
"""
637
644
Set 3D y limits.
@@ -765,7 +772,7 @@ def get_zlim3d(self):
765
772
return self .zz_viewLim .intervalx
766
773
get_zlim = get_zlim3d
767
774
768
- def get_zscale (self ) :
775
+ def get_zscale (self ):
769
776
"""
770
777
Return the zaxis scale string %s
771
778
@@ -776,7 +783,7 @@ def get_zscale(self) :
776
783
777
784
# We need to slightly redefine these to pass scalez=False
778
785
# to their calls of autoscale_view.
779
- def set_xscale (self , value , ** kwargs ) :
786
+ def set_xscale (self , value , ** kwargs ):
780
787
self .xaxis ._set_scale (value , ** kwargs )
781
788
self .autoscale_view (scaley = False , scalez = False )
782
789
self ._update_transScale ()
@@ -787,7 +794,7 @@ def set_xscale(self, value, **kwargs) :
787
794
This function was added, but not tested. Please report any bugs.
788
795
"""
789
796
790
- def set_yscale (self , value , ** kwargs ) :
797
+ def set_yscale (self , value , ** kwargs ):
791
798
self .yaxis ._set_scale (value , ** kwargs )
792
799
self .autoscale_view (scalex = False , scalez = False )
793
800
self ._update_transScale ()
@@ -800,7 +807,7 @@ def set_yscale(self, value, **kwargs) :
800
807
"""
801
808
802
809
@docstring .dedent_interpd
803
- def set_zscale (self , value , ** kwargs ) :
810
+ def set_zscale (self , value , ** kwargs ):
804
811
"""
805
812
Set the scaling of the z-axis: %(scale)s
806
813
@@ -846,7 +853,7 @@ def get_zticks(self, minor=False):
846
853
"""
847
854
return self .zaxis .get_ticklocs (minor = minor )
848
855
849
- def get_zmajorticklabels (self ) :
856
+ def get_zmajorticklabels (self ):
850
857
"""
851
858
Get the ztick labels as a list of Text instances
852
859
@@ -855,7 +862,7 @@ def get_zmajorticklabels(self) :
855
862
return cbook .silent_list ('Text zticklabel' ,
856
863
self .zaxis .get_majorticklabels ())
857
864
858
- def get_zminorticklabels (self ) :
865
+ def get_zminorticklabels (self ):
859
866
"""
860
867
Get the ztick labels as a list of Text instances
861
868
@@ -868,7 +875,7 @@ def get_zminorticklabels(self) :
868
875
return cbook .silent_list ('Text zticklabel' ,
869
876
self .zaxis .get_minorticklabels ())
870
877
871
- def set_zticklabels (self , * args , ** kwargs ) :
878
+ def set_zticklabels (self , * args , ** kwargs ):
872
879
"""
873
880
Set z-axis tick labels.
874
881
See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.
@@ -880,7 +887,7 @@ def set_zticklabels(self, *args, **kwargs) :
880
887
"""
881
888
return self .zaxis .set_ticklabels (* args , ** kwargs )
882
889
883
- def get_zticklabels (self , minor = False ) :
890
+ def get_zticklabels (self , minor = False ):
884
891
"""
885
892
Get ztick labels as a list of Text instances.
886
893
See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.
@@ -893,7 +900,7 @@ def get_zticklabels(self, minor=False) :
893
900
return cbook .silent_list ('Text zticklabel' ,
894
901
self .zaxis .get_ticklabels (minor = minor ))
895
902
896
- def zaxis_date (self , tz = None ) :
903
+ def zaxis_date (self , tz = None ):
897
904
"""
898
905
Sets up z-axis ticks and labels that treat the z data as dates.
899
906
@@ -910,7 +917,7 @@ def zaxis_date(self, tz=None) :
910
917
"""
911
918
self .zaxis .axis_date (tz )
912
919
913
- def get_zticklines (self ) :
920
+ def get_zticklines (self ):
914
921
"""
915
922
Get ztick lines as a list of Line2D instances.
916
923
Note that this function is provided merely for completeness.
@@ -1033,15 +1040,15 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
1033
1040
self ._rotate_btn = np .atleast_1d (rotate_btn ).tolist ()
1034
1041
self ._zoom_btn = np .atleast_1d (zoom_btn ).tolist ()
1035
1042
1036
- def can_zoom (self ) :
1043
+ def can_zoom (self ):
1037
1044
"""
1038
1045
Return *True* if this axes supports the zoom box button functionality.
1039
1046
1040
1047
3D axes objects do not use the zoom box button.
1041
1048
"""
1042
1049
return False
1043
1050
1044
- def can_pan (self ) :
1051
+ def can_pan (self ):
1045
1052
"""
1046
1053
Return *True* if this axes supports the pan/zoom button functionality.
1047
1054
@@ -1200,7 +1207,7 @@ def set_zlabel(self, zlabel, fontdict=None, labelpad=None, **kwargs):
1200
1207
if labelpad is not None : self .zaxis .labelpad = labelpad
1201
1208
return self .zaxis .set_label_text (zlabel , fontdict , ** kwargs )
1202
1209
1203
- def get_zlabel (self ) :
1210
+ def get_zlabel (self ):
1204
1211
"""
1205
1212
Get the z-label text string.
1206
1213
@@ -1271,12 +1278,12 @@ def grid(self, b=True, **kwargs):
1271
1278
This function was changed, but not tested. Please report any bugs.
1272
1279
'''
1273
1280
# TODO: Operate on each axes separately
1274
- if len (kwargs ) :
1281
+ if len (kwargs ):
1275
1282
b = True
1276
1283
self ._draw_grid = cbook ._string_to_bool (b )
1277
1284
self .stale = True
1278
1285
1279
- def ticklabel_format (self , ** kwargs ) :
1286
+ def ticklabel_format (self , ** kwargs ):
1280
1287
"""
1281
1288
Convenience method for manipulating the ScalarFormatter
1282
1289
used by default for linear axes in Axed3D objects.
@@ -1339,7 +1346,7 @@ def ticklabel_format(self, **kwargs) :
1339
1346
raise AttributeError (
1340
1347
"This method only works with the ScalarFormatter." )
1341
1348
1342
- def locator_params (self , axis = 'both' , tight = None , ** kwargs ) :
1349
+ def locator_params (self , axis = 'both' , tight = None , ** kwargs ):
1343
1350
"""
1344
1351
Convenience method for controlling tick locators.
1345
1352
@@ -1364,7 +1371,7 @@ def locator_params(self, axis='both', tight=None, **kwargs) :
1364
1371
self .zaxis .get_major_locator ().set_params (** kwargs )
1365
1372
self .autoscale_view (tight = tight , scalex = _x , scaley = _y , scalez = _z )
1366
1373
1367
- def tick_params (self , axis = 'both' , ** kwargs ) :
1374
+ def tick_params (self , axis = 'both' , ** kwargs ):
1368
1375
"""
1369
1376
Convenience method for changing the appearance of ticks and
1370
1377
tick labels.
@@ -1465,8 +1472,6 @@ def set_zbound(self, lower=None, upper=None):
1465
1472
else :
1466
1473
self .set_zlim (upper , lower , auto = None )
1467
1474
1468
-
1469
-
1470
1475
def text (self , x , y , z , s , zdir = None , ** kwargs ):
1471
1476
'''
1472
1477
Add text to the plot. kwargs will be passed on to Axes.text,
@@ -1654,7 +1659,7 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
1654
1659
for rs in xrange (0 , rows - 1 , rstride ):
1655
1660
for cs in xrange (0 , cols - 1 , cstride ):
1656
1661
ps = []
1657
- for a in (X , Y , Z ) :
1662
+ for a in (X , Y , Z ):
1658
1663
ztop = a [rs ,cs :min (cols , cs + cstride + 1 )]
1659
1664
zleft = a [rs + 1 :min (rows , rs + rstride + 1 ),
1660
1665
min (cols - 1 , cs + cstride )]
@@ -1838,14 +1843,14 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
1838
1843
if rstride :
1839
1844
rii = list (xrange (0 , rows , rstride ))
1840
1845
# Add the last index only if needed
1841
- if rows > 0 and rii [- 1 ] != (rows - 1 ) :
1846
+ if rows > 0 and rii [- 1 ] != (rows - 1 ):
1842
1847
rii += [rows - 1 ]
1843
1848
else :
1844
1849
rii = []
1845
1850
if cstride :
1846
1851
cii = list (xrange (0 , cols , cstride ))
1847
1852
# Add the last index only if needed
1848
- if cols > 0 and cii [- 1 ] != (cols - 1 ) :
1853
+ if cols > 0 and cii [- 1 ] != (cols - 1 ):
1849
1854
cii += [cols - 1 ]
1850
1855
else :
1851
1856
cii = []
@@ -2061,9 +2066,9 @@ def add_contour_set(self, cset, extend3d=False, stride=5, zdir='z', offset=None)
2061
2066
z = offset
2062
2067
art3d .line_collection_2d_to_3d (linec , z , zdir = zdir )
2063
2068
2064
- def add_contourf_set (self , cset , zdir = 'z' , offset = None ) :
2069
+ def add_contourf_set (self , cset , zdir = 'z' , offset = None ):
2065
2070
zdir = '-' + zdir
2066
- for z , linec in zip (cset .levels , cset .collections ) :
2071
+ for z , linec in zip (cset .levels , cset .collections ):
2067
2072
if offset is not None :
2068
2073
z = offset
2069
2074
art3d .poly_collection_2d_to_3d (linec , z , zdir = zdir )
0 commit comments