Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec8cf08

Browse files
authored
Merge pull request #7859 from anntzer/set_autoscalez_on
Fix typo in Axes3D.set_autoscalez_on.
2 parents 0dfd271 + effe642 commit ec8cf08

File tree

2 files changed

+67
-50
lines changed

2 files changed

+67
-50
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import warnings
1919

20+
import numpy as np
2021
import matplotlib.axes as maxes
2122
from matplotlib.axes import Axes, rcParams
2223
from matplotlib import cbook
@@ -26,18 +27,19 @@
2627
from matplotlib import docstring
2728
import matplotlib.scale as mscale
2829
from matplotlib.tri.triangulation import Triangulation
29-
import numpy as np
3030
from matplotlib import colors as mcolors
3131
from matplotlib.colors import Normalize, LightSource
3232

3333
from . import art3d
3434
from . import proj3d
3535
from . import axis3d
3636

37+
3738
def unit_bbox():
3839
box = Bbox(np.array([[0, 0], [1, 1]]))
3940
return box
4041

42+
4143
class Axes3D(Axes):
4244
"""
4345
3D axes object.
@@ -302,7 +304,7 @@ def get_axis_position(self):
302304
def update_datalim(self, xys, **kwargs):
303305
pass
304306

305-
def get_autoscale_on(self) :
307+
def get_autoscale_on(self):
306308
"""
307309
Get whether autoscaling is applied for all axes on plot commands
308310
@@ -311,7 +313,7 @@ def get_autoscale_on(self) :
311313
"""
312314
return Axes.get_autoscale_on(self) and self.get_autoscalez_on()
313315

314-
def get_autoscalez_on(self) :
316+
def get_autoscalez_on(self):
315317
"""
316318
Get whether autoscaling for the z-axis is applied on plot commands
317319
@@ -320,7 +322,7 @@ def get_autoscalez_on(self) :
320322
"""
321323
return self._autoscaleZon
322324

323-
def set_autoscale_on(self, b) :
325+
def set_autoscale_on(self, b):
324326
"""
325327
Set whether autoscaling is applied on plot commands
326328
@@ -332,7 +334,7 @@ def set_autoscale_on(self, b) :
332334
Axes.set_autoscale_on(self, b)
333335
self.set_autoscalez_on(b)
334336

335-
def set_autoscalez_on(self, b) :
337+
def set_autoscalez_on(self, b):
336338
"""
337339
Set whether autoscaling for the z-axis is applied on plot commands
338340
@@ -341,9 +343,9 @@ def set_autoscalez_on(self, b) :
341343
.. versionadded :: 1.1.0
342344
This function was added, but not tested. Please report any bugs.
343345
"""
344-
self._autoscalez_on = b
346+
self._autoscaleZon = b
345347

346-
def set_zmargin(self, m) :
348+
def set_zmargin(self, m):
347349
"""
348350
Set padding of Z data limits prior to autoscaling.
349351
@@ -360,7 +362,7 @@ def set_zmargin(self, m) :
360362
self._zmargin = m
361363
self.stale = True
362364

363-
def margins(self, *args, **kw) :
365+
def margins(self, *args, **kw):
364366
"""
365367
Convenience method to set or retrieve autoscaling margins.
366368
@@ -403,30 +405,36 @@ def margins(self, *args, **kw) :
403405
mx = kw.pop('x', None)
404406
my = kw.pop('y', None)
405407
mz = kw.pop('z', None)
406-
if len(args) == 1:
408+
if not args:
409+
pass
410+
elif len(args) == 1:
407411
mx = my = mz = args[0]
408412
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)
410417
mx, my = args
411418
elif len(args) == 3:
412419
mx, my, mz = args
413420
else:
414-
raise ValueError("more than three arguments were supplied")
421+
raise ValueError(
422+
"Axes3D.margins takes at most three positional arguments")
415423
if mx is not None:
416424
self.set_xmargin(mx)
417425
if my is not None:
418426
self.set_ymargin(my)
419427
if mz is not None:
420428
self.set_zmargin(mz)
421429

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
425433

426434
self.autoscale_view(tight=tight, scalex=scalex, scaley=scaley,
427435
scalez=scalez)
428436

429-
def autoscale(self, enable=True, axis='both', tight=None) :
437+
def autoscale(self, enable=True, axis='both', tight=None):
430438
"""
431439
Convenience method for simple axis view autoscaling.
432440
See :meth:`matplotlib.axes.Axes.autoscale` for full explanation.
@@ -442,18 +450,18 @@ def autoscale(self, enable=True, axis='both', tight=None) :
442450
scaley = True
443451
scalez = True
444452
else:
445-
scalex = False
446-
scaley = False
447-
scalez = False
448453
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
451457
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
454461
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
457465
self.autoscale_view(tight=tight, scalex=scalex, scaley=scaley,
458466
scalez=scalez)
459467

@@ -477,7 +485,7 @@ def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
477485
self.autoscale_view()
478486

479487
def autoscale_view(self, tight=None, scalex=True, scaley=True,
480-
scalez=True) :
488+
scalez=True):
481489
"""
482490
Autoscale the view limits using the data limits.
483491
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):
631639
return left, right
632640
set_xlim = set_xlim3d
633641

634-
635642
def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
636643
"""
637644
Set 3D y limits.
@@ -765,7 +772,7 @@ def get_zlim3d(self):
765772
return self.zz_viewLim.intervalx
766773
get_zlim = get_zlim3d
767774

768-
def get_zscale(self) :
775+
def get_zscale(self):
769776
"""
770777
Return the zaxis scale string %s
771778
@@ -776,7 +783,7 @@ def get_zscale(self) :
776783

777784
# We need to slightly redefine these to pass scalez=False
778785
# to their calls of autoscale_view.
779-
def set_xscale(self, value, **kwargs) :
786+
def set_xscale(self, value, **kwargs):
780787
self.xaxis._set_scale(value, **kwargs)
781788
self.autoscale_view(scaley=False, scalez=False)
782789
self._update_transScale()
@@ -787,7 +794,7 @@ def set_xscale(self, value, **kwargs) :
787794
This function was added, but not tested. Please report any bugs.
788795
"""
789796

790-
def set_yscale(self, value, **kwargs) :
797+
def set_yscale(self, value, **kwargs):
791798
self.yaxis._set_scale(value, **kwargs)
792799
self.autoscale_view(scalex=False, scalez=False)
793800
self._update_transScale()
@@ -800,7 +807,7 @@ def set_yscale(self, value, **kwargs) :
800807
"""
801808

802809
@docstring.dedent_interpd
803-
def set_zscale(self, value, **kwargs) :
810+
def set_zscale(self, value, **kwargs):
804811
"""
805812
Set the scaling of the z-axis: %(scale)s
806813
@@ -846,7 +853,7 @@ def get_zticks(self, minor=False):
846853
"""
847854
return self.zaxis.get_ticklocs(minor=minor)
848855

849-
def get_zmajorticklabels(self) :
856+
def get_zmajorticklabels(self):
850857
"""
851858
Get the ztick labels as a list of Text instances
852859
@@ -855,7 +862,7 @@ def get_zmajorticklabels(self) :
855862
return cbook.silent_list('Text zticklabel',
856863
self.zaxis.get_majorticklabels())
857864

858-
def get_zminorticklabels(self) :
865+
def get_zminorticklabels(self):
859866
"""
860867
Get the ztick labels as a list of Text instances
861868
@@ -868,7 +875,7 @@ def get_zminorticklabels(self) :
868875
return cbook.silent_list('Text zticklabel',
869876
self.zaxis.get_minorticklabels())
870877

871-
def set_zticklabels(self, *args, **kwargs) :
878+
def set_zticklabels(self, *args, **kwargs):
872879
"""
873880
Set z-axis tick labels.
874881
See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.
@@ -880,7 +887,7 @@ def set_zticklabels(self, *args, **kwargs) :
880887
"""
881888
return self.zaxis.set_ticklabels(*args, **kwargs)
882889

883-
def get_zticklabels(self, minor=False) :
890+
def get_zticklabels(self, minor=False):
884891
"""
885892
Get ztick labels as a list of Text instances.
886893
See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.
@@ -893,7 +900,7 @@ def get_zticklabels(self, minor=False) :
893900
return cbook.silent_list('Text zticklabel',
894901
self.zaxis.get_ticklabels(minor=minor))
895902

896-
def zaxis_date(self, tz=None) :
903+
def zaxis_date(self, tz=None):
897904
"""
898905
Sets up z-axis ticks and labels that treat the z data as dates.
899906
@@ -910,7 +917,7 @@ def zaxis_date(self, tz=None) :
910917
"""
911918
self.zaxis.axis_date(tz)
912919

913-
def get_zticklines(self) :
920+
def get_zticklines(self):
914921
"""
915922
Get ztick lines as a list of Line2D instances.
916923
Note that this function is provided merely for completeness.
@@ -1033,15 +1040,15 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
10331040
self._rotate_btn = np.atleast_1d(rotate_btn).tolist()
10341041
self._zoom_btn = np.atleast_1d(zoom_btn).tolist()
10351042

1036-
def can_zoom(self) :
1043+
def can_zoom(self):
10371044
"""
10381045
Return *True* if this axes supports the zoom box button functionality.
10391046
10401047
3D axes objects do not use the zoom box button.
10411048
"""
10421049
return False
10431050

1044-
def can_pan(self) :
1051+
def can_pan(self):
10451052
"""
10461053
Return *True* if this axes supports the pan/zoom button functionality.
10471054
@@ -1200,7 +1207,7 @@ def set_zlabel(self, zlabel, fontdict=None, labelpad=None, **kwargs):
12001207
if labelpad is not None : self.zaxis.labelpad = labelpad
12011208
return self.zaxis.set_label_text(zlabel, fontdict, **kwargs)
12021209

1203-
def get_zlabel(self) :
1210+
def get_zlabel(self):
12041211
"""
12051212
Get the z-label text string.
12061213
@@ -1271,12 +1278,12 @@ def grid(self, b=True, **kwargs):
12711278
This function was changed, but not tested. Please report any bugs.
12721279
'''
12731280
# TODO: Operate on each axes separately
1274-
if len(kwargs) :
1281+
if len(kwargs):
12751282
b = True
12761283
self._draw_grid = cbook._string_to_bool(b)
12771284
self.stale = True
12781285

1279-
def ticklabel_format(self, **kwargs) :
1286+
def ticklabel_format(self, **kwargs):
12801287
"""
12811288
Convenience method for manipulating the ScalarFormatter
12821289
used by default for linear axes in Axed3D objects.
@@ -1339,7 +1346,7 @@ def ticklabel_format(self, **kwargs) :
13391346
raise AttributeError(
13401347
"This method only works with the ScalarFormatter.")
13411348

1342-
def locator_params(self, axis='both', tight=None, **kwargs) :
1349+
def locator_params(self, axis='both', tight=None, **kwargs):
13431350
"""
13441351
Convenience method for controlling tick locators.
13451352
@@ -1364,7 +1371,7 @@ def locator_params(self, axis='both', tight=None, **kwargs) :
13641371
self.zaxis.get_major_locator().set_params(**kwargs)
13651372
self.autoscale_view(tight=tight, scalex=_x, scaley=_y, scalez=_z)
13661373

1367-
def tick_params(self, axis='both', **kwargs) :
1374+
def tick_params(self, axis='both', **kwargs):
13681375
"""
13691376
Convenience method for changing the appearance of ticks and
13701377
tick labels.
@@ -1465,8 +1472,6 @@ def set_zbound(self, lower=None, upper=None):
14651472
else :
14661473
self.set_zlim(upper, lower, auto=None)
14671474

1468-
1469-
14701475
def text(self, x, y, z, s, zdir=None, **kwargs):
14711476
'''
14721477
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):
16541659
for rs in xrange(0, rows-1, rstride):
16551660
for cs in xrange(0, cols-1, cstride):
16561661
ps = []
1657-
for a in (X, Y, Z) :
1662+
for a in (X, Y, Z):
16581663
ztop = a[rs,cs:min(cols, cs+cstride+1)]
16591664
zleft = a[rs+1:min(rows, rs+rstride+1),
16601665
min(cols-1, cs+cstride)]
@@ -1838,14 +1843,14 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
18381843
if rstride:
18391844
rii = list(xrange(0, rows, rstride))
18401845
# 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):
18421847
rii += [rows-1]
18431848
else:
18441849
rii = []
18451850
if cstride:
18461851
cii = list(xrange(0, cols, cstride))
18471852
# 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):
18491854
cii += [cols-1]
18501855
else:
18511856
cii = []
@@ -2061,9 +2066,9 @@ def add_contour_set(self, cset, extend3d=False, stride=5, zdir='z', offset=None)
20612066
z = offset
20622067
art3d.line_collection_2d_to_3d(linec, z, zdir=zdir)
20632068

2064-
def add_contourf_set(self, cset, zdir='z', offset=None) :
2069+
def add_contourf_set(self, cset, zdir='z', offset=None):
20652070
zdir = '-' + zdir
2066-
for z, linec in zip(cset.levels, cset.collections) :
2071+
for z, linec in zip(cset.levels, cset.collections):
20672072
if offset is not None :
20682073
z = offset
20692074
art3d.poly_collection_2d_to_3d(linec, z, zdir=zdir)

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,15 @@ def test_lines_dists():
468468

469469
ax.set_xlim(-50, 150)
470470
ax.set_ylim(0, 300)
471+
472+
473+
@cleanup
474+
def test_autoscale():
475+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
476+
ax.margins(x=0, y=.1, z=.2)
477+
ax.plot([0, 1], [0, 1], [0, 1])
478+
assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.2, 1.2)
479+
ax.autoscale(False)
480+
ax.set_autoscalez_on(True)
481+
ax.plot([0, 2], [0, 2], [0, 2])
482+
assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.4, 2.4)

0 commit comments

Comments
 (0)