@@ -267,8 +267,8 @@ def tunit_edges(self, vals=None, M=None):
267
267
(tc [7 ], tc [4 ])]
268
268
return edges
269
269
270
- def set_aspect (
271
- self , aspect , adjustable = 'datalim' , anchor = None , share = False ):
270
+ def set_aspect (self , aspect , adjustable = 'datalim' , anchor = None ,
271
+ share = False ):
272
272
"""
273
273
Set the aspect ratios.
274
274
@@ -350,28 +350,18 @@ def set_aspect(
350
350
if i in ax_indices :
351
351
set_lim (mean [i ] - deltas [i ]/ 2. , mean [i ] + deltas [i ]/ 2. )
352
352
elif adjustable == 'box' :
353
+ # Change the box aspect such that the ratio of the length of
354
+ # the unmodified axis to the length of the diagonal
355
+ # perpendicular to it remains unchanged.
353
356
deltas = np .ptp (view_intervals , axis = 1 )
354
- box_aspect = self .get_box_aspect ()
355
- if aspect == 'equal' :
356
- box_aspect = np .ptp (view_intervals , axis = 1 )
357
- elif aspect == 'equalxy' :
358
- old_diag = box_aspect [0 ] ** 2 + box_aspect [1 ] ** 2
359
- new_diag = deltas [0 ] ** 2 + deltas [1 ] ** 2
360
- box_aspect [0 ] = deltas [0 ]
361
- box_aspect [1 ] = deltas [1 ]
362
- box_aspect [2 ] *= np .sqrt (new_diag / old_diag )
363
- elif aspect == 'equalxz' :
364
- old_diag = box_aspect [0 ] ** 2 + box_aspect [2 ] ** 2
365
- new_diag = deltas [0 ] ** 2 + deltas [2 ] ** 2
366
- box_aspect [0 ] = deltas [0 ]
367
- box_aspect [1 ] *= np .sqrt (new_diag / old_diag )
368
- box_aspect [2 ] = deltas [2 ]
369
- elif aspect == 'equalyz' :
370
- old_diag = box_aspect [1 ] ** 2 + box_aspect [2 ] ** 2
371
- new_diag = deltas [1 ] ** 2 + deltas [2 ] ** 2
372
- box_aspect [0 ] *= np .sqrt (new_diag / old_diag )
373
- box_aspect [1 ] = deltas [1 ]
374
- box_aspect [2 ] = deltas [2 ]
357
+ box_aspect = np .array (self .get_box_aspect ())
358
+ box_aspect [ax_indices ] = deltas [ax_indices ]
359
+ remaining_ax_indices = {0 , 1 , 2 }.difference (ax_indices )
360
+ if remaining_ax_indices :
361
+ remaining_ax_index = remaining_ax_indices .pop ()
362
+ old_diag = np .linalg .norm (box_aspect [ax_indices ])
363
+ new_diag = np .linalg .norm (deltas [ax_indices ])
364
+ box_aspect [remaining_ax_index ] *= new_diag / old_diag
375
365
self .set_box_aspect (box_aspect )
376
366
377
367
def set_box_aspect (self , aspect , * , zoom = 1 ):
0 commit comments