@@ -267,8 +267,7 @@ def tunit_edges(self, vals=None, M=None):
267267 (tc [7 ], tc [4 ])]
268268 return edges
269269
270- def set_aspect (self , aspect , adjustable = 'datalim' , anchor = None ,
271- share = False ):
270+ def set_aspect (self , aspect , adjustable = None , anchor = None , share = False ):
272271 """
273272 Set the aspect ratios.
274273
@@ -287,9 +286,10 @@ def set_aspect(self, aspect, adjustable='datalim', anchor=None,
287286 'equalyz' adapt the y and z axes to have equal aspect ratios.
288287 ========= ==================================================
289288
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.
289+ adjustable : None or {'box', 'datalim'}, optional
290+ If not *None*, this defines which parameter will be adjusted to
291+ meet the required aspect. See `.set_adjustable` for further
292+ details.
293293
294294 anchor : None or str or 2-tuple of float, optional
295295 If not *None*, this defines where the Axes will be drawn if there
@@ -317,50 +317,66 @@ def set_aspect(self, aspect, adjustable='datalim', anchor=None,
317317 """
318318 _api .check_in_list (('auto' , 'equal' , 'equalxy' , 'equalyz' , 'equalxz' ),
319319 aspect = aspect )
320- _api .check_in_list (('datalim' , 'box' ), adjustable = adjustable )
320+ if adjustable is None :
321+ adjustable = self ._adjustable
322+ _api .check_in_list (('box' , 'datalim' ), adjustable = adjustable )
321323 super ().set_aspect (
322324 aspect = 'auto' , adjustable = adjustable , anchor = anchor , share = share )
323325 self ._aspect = aspect
324326
325327 if aspect in ('equal' , 'equalxy' , 'equalxz' , 'equalyz' ):
326- if aspect == 'equal' :
327- ax_indices = [0 , 1 , 2 ]
328- elif aspect == 'equalxy' :
329- ax_indices = [0 , 1 ]
330- elif aspect == 'equalxz' :
331- ax_indices = [0 , 2 ]
332- elif aspect == 'equalyz' :
333- ax_indices = [1 , 2 ]
328+ ax_idx = self ._equal_aspect_axis_indices (aspect )
334329
335330 view_intervals = np .array ([self .xaxis .get_view_interval (),
336331 self .yaxis .get_view_interval (),
337332 self .zaxis .get_view_interval ()])
338333 ptp = np .ptp (view_intervals , axis = 1 )
339334 if adjustable == 'datalim' :
340335 mean = np .mean (view_intervals , axis = 1 )
341- delta = max (ptp [ax_indices ])
336+ delta = max (ptp [ax_idx ])
342337 scale = self ._box_aspect [ptp == delta ][0 ]
343338 deltas = delta * self ._box_aspect / scale
344339
345340 for i , set_lim in enumerate ((self .set_xlim3d ,
346341 self .set_ylim3d ,
347342 self .set_zlim3d )):
348- if i in ax_indices :
343+ if i in ax_idx :
349344 set_lim (mean [i ] - deltas [i ]/ 2. , mean [i ] + deltas [i ]/ 2. )
350345 else : # 'box'
351346 # Change the box aspect such that the ratio of the length of
352347 # the unmodified axis to the length of the diagonal
353348 # perpendicular to it remains unchanged.
354349 box_aspect = np .array (self ._box_aspect )
355- box_aspect [ax_indices ] = ptp [ax_indices ]
356- remaining_ax_indices = {0 , 1 , 2 }.difference (ax_indices )
357- if remaining_ax_indices :
358- remaining_ax_index = remaining_ax_indices .pop ()
359- old_diag = np .linalg .norm (box_aspect [ ax_indices ])
360- new_diag = np .linalg .norm (ptp [ ax_indices ])
361- box_aspect [remaining_ax_index ] *= new_diag / old_diag
350+ box_aspect [ax_idx ] = ptp [ax_idx ]
351+ remaining_ax_idx = {0 , 1 , 2 }.difference (ax_idx )
352+ if remaining_ax_idx :
353+ remaining = remaining_ax_idx .pop ()
354+ old_diag = np .linalg .norm (self . _box_aspect [ ax_idx ])
355+ new_diag = np .linalg .norm (box_aspect [ ax_idx ])
356+ box_aspect [remaining ] *= new_diag / old_diag
362357 self .set_box_aspect (box_aspect )
363358
359+ def _equal_aspect_axis_indices (self , aspect ):
360+ """
361+ Get the indices for which of the x, y, z axes are constrained to have
362+ equal aspect ratios.
363+
364+ Parameters
365+ ----------
366+ aspect : {'auto', 'equal', 'equalxy', 'equalxz', 'equalyz'}
367+ See descriptions in docstring for `.set_aspect()`.
368+ """
369+ ax_indices = [] # aspect == 'auto'
370+ if aspect == 'equal' :
371+ ax_indices = [0 , 1 , 2 ]
372+ elif aspect == 'equalxy' :
373+ ax_indices = [0 , 1 ]
374+ elif aspect == 'equalxz' :
375+ ax_indices = [0 , 2 ]
376+ elif aspect == 'equalyz' :
377+ ax_indices = [1 , 2 ]
378+ return ax_indices
379+
364380 def set_box_aspect (self , aspect , * , zoom = 1 ):
365381 """
366382 Set the Axes box aspect.
0 commit comments