Skip to content

Commit effe642

Browse files
committed
Fix passing kwargs only to margins; add test.
1 parent 5347d49 commit effe642

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,21 @@ def margins(self, *args, **kw):
405405
mx = kw.pop('x', None)
406406
my = kw.pop('y', None)
407407
mz = kw.pop('z', None)
408-
if len(args) == 1:
408+
if not args:
409+
pass
410+
elif len(args) == 1:
409411
mx = my = mz = args[0]
410412
elif len(args) == 2:
411-
# 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)
412417
mx, my = args
413418
elif len(args) == 3:
414419
mx, my, mz = args
415420
else:
416-
raise ValueError("more than three arguments were supplied")
421+
raise ValueError(
422+
"Axes3D.margins takes at most three positional arguments")
417423
if mx is not None:
418424
self.set_xmargin(mx)
419425
if my is not None:
@@ -444,18 +450,18 @@ def autoscale(self, enable=True, axis='both', tight=None):
444450
scaley = True
445451
scalez = True
446452
else:
447-
scalex = False
448-
scaley = False
449-
scalez = False
450453
if axis in ['x', 'both']:
451-
self._autoscaleXon = bool(enable)
452-
scalex = self._autoscaleXon
454+
self._autoscaleXon = scalex = bool(enable)
455+
else:
456+
scalex = False
453457
if axis in ['y', 'both']:
454-
self._autoscaleYon = bool(enable)
455-
scaley = self._autoscaleYon
458+
self._autoscaleYon = scaley = bool(enable)
459+
else:
460+
scaley = False
456461
if axis in ['z', 'both']:
457-
self._autoscaleZon = bool(enable)
458-
scalez = self._autoscaleZon
462+
self._autoscaleZon = scalez = bool(enable)
463+
else:
464+
scalez = False
459465
self.autoscale_view(tight=tight, scalex=scalex, scaley=scaley,
460466
scalez=scalez)
461467

lib/mpl_toolkits/tests/test_mplot3d.py

+12
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)