Skip to content

Commit b5fc59d

Browse files
git push -f# This is a combination of 2 commits.
Clean up 3d plot box_aspect zooming linting Cleanup
1 parent 92989c3 commit b5fc59d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def __init__(
129129
# they can't be defined until Axes.__init__ has been called
130130
self.view_init(self.initial_elev, self.initial_azim, self.initial_roll)
131131

132+
# set the initial zoom level
133+
self.zoom = 1
134+
132135
self._sharez = sharez
133136
if sharez is not None:
134137
self._shared_axes["z"].join(self, sharez)
@@ -329,7 +332,7 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
329332
super().set_aspect(
330333
aspect, adjustable=adjustable, anchor=anchor, share=share)
331334

332-
def set_box_aspect(self, aspect, *, zoom=1):
335+
def set_box_aspect(self, aspect=None, *, zoom=None):
333336
"""
334337
Set the axes box aspect.
335338
@@ -346,22 +349,27 @@ def set_box_aspect(self, aspect, *, zoom=1):
346349
347350
Parameters
348351
----------
349-
aspect : 3-tuple of floats or None
352+
aspect : 3-tuple of floats or None, default: (4:4:3)
350353
Changes the physical dimensions of the Axes3D, such that the ratio
351354
of the axis lengths in display units is x:y:z.
352355
353-
If None, defaults to 4:4:3
354-
355-
zoom : float
356-
Control overall size of the Axes3D in the figure.
356+
zoom : float, default: None
357+
Control overall size of the Axes3D in the figure. A value of None
358+
keeps the current zoom level.
357359
"""
360+
# self.zoom is first set in Axes3D init
361+
if zoom is not None:
362+
if zoom <= 0:
363+
raise ValueError(f'Argument zoom = {zoom} must be > 0')
364+
self.zoom = zoom
365+
358366
if aspect is None:
359367
aspect = np.asarray((4, 4, 3), dtype=float)
360368
else:
361369
aspect = np.asarray(aspect, dtype=float)
362370
_api.check_shape((3,), aspect=aspect)
363371
# default scale tuned to match the mpl32 appearance.
364-
aspect *= 1.8294640721620434 * zoom / np.linalg.norm(aspect)
372+
aspect *= 1.8294640721620434 * self.zoom / np.linalg.norm(aspect)
365373

366374
self._box_aspect = aspect
367375
self.stale = True
@@ -1006,7 +1014,7 @@ def view_init(self, elev=None, azim=None, roll=None, vertical_axis="z"):
10061014
The axis to align vertically. *azim* rotates about this axis.
10071015
"""
10081016

1009-
self.dist = 10
1017+
self.dist = 10 # The camera distance from origin. Behaves like zoom
10101018

10111019
if elev is None:
10121020
self.elev = self.initial_elev

0 commit comments

Comments
 (0)