Skip to content

Commit e69051e

Browse files
Clean up 3d plot box_aspect zooming
linting Cleanup Make zoom and dist private attrs Deprecate Axes3D.dist Deprecate Axes3D.dist
1 parent 4af95cb commit e69051e

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``Axes3D.dist``
2+
~~~~~~~~~~~~~~~
3+
... has been privatized. Use the ``zoom`` keyword argument in
4+
``Axes3D.set_box_aspect`` instead.

lib/mpl_toolkits/mplot3d/axes3d.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Axes3D(Axes):
5353
_axis_names = ("x", "y", "z")
5454
Axes._shared_axes["z"] = cbook.Grouper()
5555

56+
dist = _api.deprecate_privatize_attribute("3.6")
57+
5658
def __init__(
5759
self, fig, rect=None, *args,
5860
elev=30, azim=-60, roll=0, sharez=None, proj_type='persp',
@@ -198,10 +200,10 @@ def convert_zunits(self, z):
198200
def set_top_view(self):
199201
# this happens to be the right view for the viewing coordinates
200202
# moved up and to the left slightly to fit labels and axes
201-
xdwl = 0.95 / self.dist
202-
xdw = 0.9 / self.dist
203-
ydwl = 0.95 / self.dist
204-
ydw = 0.9 / self.dist
203+
xdwl = 0.95 / self._dist
204+
xdw = 0.9 / self._dist
205+
ydwl = 0.95 / self._dist
206+
ydw = 0.9 / self._dist
205207
# This is purposely using the 2D Axes's set_xlim and set_ylim,
206208
# because we are trying to place our viewing pane.
207209
super().set_xlim(-xdwl, xdw, auto=None)
@@ -349,12 +351,14 @@ def set_box_aspect(self, aspect, *, zoom=1):
349351
aspect : 3-tuple of floats or None
350352
Changes the physical dimensions of the Axes3D, such that the ratio
351353
of the axis lengths in display units is x:y:z.
354+
If None, defaults to (4,4,3).
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: 1
357+
Control overall size of the Axes3D in the figure. Must be > 0.
357358
"""
359+
if zoom <= 0:
360+
raise ValueError(f'Argument zoom = {zoom} must be > 0')
361+
358362
if aspect is None:
359363
aspect = np.asarray((4, 4, 3), dtype=float)
360364
else:
@@ -1006,7 +1010,7 @@ def view_init(self, elev=None, azim=None, roll=None, vertical_axis="z"):
10061010
The axis to align vertically. *azim* rotates about this axis.
10071011
"""
10081012

1009-
self.dist = 10
1013+
self._dist = 10 # The camera distance from origin. Behaves like zoom
10101014

10111015
if elev is None:
10121016
self.elev = self.initial_elev
@@ -1081,7 +1085,7 @@ def get_proj(self):
10811085

10821086
# The coordinates for the eye viewing point. The eye is looking
10831087
# towards the middle of the box of data from a distance:
1084-
eye = R + self.dist * ps
1088+
eye = R + self._dist * ps
10851089

10861090
# TODO: Is this being used somewhere? Can it be removed?
10871091
self.eye = eye
@@ -1095,7 +1099,7 @@ def get_proj(self):
10951099
V[self._vertical_axis] = -1 if abs(elev_rad) > 0.5 * np.pi else 1
10961100

10971101
viewM = proj3d.view_transformation(eye, R, V, roll_rad)
1098-
projM = self._projection(-self.dist, self.dist)
1102+
projM = self._projection(-self._dist, self._dist)
10991103
M0 = np.dot(viewM, worldM)
11001104
M = np.dot(projM, M0)
11011105
return M

0 commit comments

Comments
 (0)