@@ -287,12 +287,9 @@ def set_aspect(self, aspect, adjustable='datalim', anchor=None,
287
287
'equalyz' adapt the y and z axes to have equal aspect ratios.
288
288
========= ==================================================
289
289
290
- adjustable : None
291
- Currently ignored by Axes3D
292
-
293
- If not *None*, this defines which parameter will be adjusted to
294
- meet the required aspect. See `.set_adjustable` for further
295
- details.
290
+ adjustable : {'datalim', 'box'}, default: 'datalim'
291
+ This defines which parameter will be adjusted to meet the required
292
+ aspect. See `.set_adjustable` for further details.
296
293
297
294
anchor : None or str or 2-tuple of float, optional
298
295
If not *None*, this defines where the Axes will be drawn if there
@@ -320,6 +317,7 @@ def set_aspect(self, aspect, adjustable='datalim', anchor=None,
320
317
"""
321
318
_api .check_in_list (('auto' , 'equal' , 'equalxy' , 'equalyz' , 'equalxz' ),
322
319
aspect = aspect )
320
+ _api .check_in_list (('datalim' , 'box' ), adjustable = adjustable )
323
321
super ().set_aspect (
324
322
aspect = 'auto' , adjustable = adjustable , anchor = anchor , share = share )
325
323
self ._aspect = aspect
@@ -337,9 +335,9 @@ def set_aspect(self, aspect, adjustable='datalim', anchor=None,
337
335
view_intervals = np .array ([self .xaxis .get_view_interval (),
338
336
self .yaxis .get_view_interval (),
339
337
self .zaxis .get_view_interval ()])
338
+ ptp = np .ptp (view_intervals , axis = 1 )
340
339
if adjustable == 'datalim' :
341
340
mean = np .mean (view_intervals , axis = 1 )
342
- ptp = np .ptp (view_intervals , axis = 1 )
343
341
delta = max (ptp [ax_indices ])
344
342
scale = self ._box_aspect [ptp == delta ][0 ]
345
343
deltas = delta * self ._box_aspect / scale
@@ -349,18 +347,17 @@ def set_aspect(self, aspect, adjustable='datalim', anchor=None,
349
347
self .set_zlim3d )):
350
348
if i in ax_indices :
351
349
set_lim (mean [i ] - deltas [i ]/ 2. , mean [i ] + deltas [i ]/ 2. )
352
- elif adjustable == 'box' :
350
+ else : # 'box'
353
351
# Change the box aspect such that the ratio of the length of
354
352
# the unmodified axis to the length of the diagonal
355
353
# perpendicular to it remains unchanged.
356
- deltas = np .ptp (view_intervals , axis = 1 )
357
- box_aspect = np .array (self .get_box_aspect ())
358
- box_aspect [ax_indices ] = deltas [ax_indices ]
354
+ box_aspect = np .array (self ._box_aspect )
355
+ box_aspect [ax_indices ] = ptp [ax_indices ]
359
356
remaining_ax_indices = {0 , 1 , 2 }.difference (ax_indices )
360
357
if remaining_ax_indices :
361
358
remaining_ax_index = remaining_ax_indices .pop ()
362
359
old_diag = np .linalg .norm (box_aspect [ax_indices ])
363
- new_diag = np .linalg .norm (deltas [ax_indices ])
360
+ new_diag = np .linalg .norm (ptp [ax_indices ])
364
361
box_aspect [remaining_ax_index ] *= new_diag / old_diag
365
362
self .set_box_aspect (box_aspect )
366
363
0 commit comments