Skip to content

Commit da0e607

Browse files
Use all available plot space
1 parent 31d1319 commit da0e607

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

doc/users/next_whats_new/3d_plot_aspects.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Users can set the aspect ratio for the X, Y, Z axes of a 3D plot to be 'equal',
1414
aspects = ('auto', 'equal', 'equalxy', 'equalyz', 'equalxz')
1515
fig, axs = plt.subplots(1, len(aspects), subplot_kw={'projection': '3d'})
1616

17-
# Draw rectangular cuboid with side lengths [1, 1, 2]
17+
# Draw rectangular cuboid with side lengths [1, 1, 5]
1818
r = [0, 1]
19-
scale = np.array([1, 1, 2])
19+
scale = np.array([1, 1, 5])
2020
pts = combinations(np.array(list(product(r, r, r))), 2)
2121
for start, end in pts:
2222
if np.sum(np.abs(start - end)) == r[1] - r[0]:

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,25 +325,27 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
325325

326326
if aspect in ('equal', 'equalxy', 'equalxz', 'equalyz'):
327327
if aspect == 'equal':
328-
axis_indices = [0, 1, 2]
328+
ax_indices = [0, 1, 2]
329329
elif aspect == 'equalxy':
330-
axis_indices = [0, 1]
330+
ax_indices = [0, 1]
331331
elif aspect == 'equalxz':
332-
axis_indices = [0, 2]
332+
ax_indices = [0, 2]
333333
elif aspect == 'equalyz':
334-
axis_indices = [1, 2]
334+
ax_indices = [1, 2]
335335

336336
view_intervals = np.array([self.xaxis.get_view_interval(),
337337
self.yaxis.get_view_interval(),
338338
self.zaxis.get_view_interval()])
339339
mean = np.mean(view_intervals, axis=1)
340-
delta = np.max(np.ptp(view_intervals, axis=1))
341-
deltas = delta * self._box_aspect / min(self._box_aspect)
340+
ptp = np.ptp(view_intervals, axis=1)
341+
delta = max(ptp[ax_indices])
342+
scale = self._box_aspect[ptp == delta][0]
343+
deltas = delta * self._box_aspect / scale
342344

343345
for i, set_lim in enumerate((self.set_xlim3d,
344346
self.set_ylim3d,
345347
self.set_zlim3d)):
346-
if i in axis_indices:
348+
if i in ax_indices:
347349
set_lim(mean[i] - deltas[i]/2., mean[i] + deltas[i]/2.)
348350

349351
def set_box_aspect(self, aspect, *, zoom=1):

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def test_aspects():
3232
aspects = ('auto', 'equal', 'equalxy', 'equalyz', 'equalxz')
3333
fig, axs = plt.subplots(1, len(aspects), subplot_kw={'projection': '3d'})
3434

35-
# Draw rectangular cuboid with side lengths [1, 1, 2]
35+
# Draw rectangular cuboid with side lengths [1, 1, 5]
3636
r = [0, 1]
37-
scale = np.array([1, 1, 2])
37+
scale = np.array([1, 1, 5])
3838
pts = itertools.combinations(np.array(list(itertools.product(r, r, r))), 2)
3939
for start, end in pts:
4040
if np.sum(np.abs(start - end)) == r[1] - r[0]:

0 commit comments

Comments
 (0)