@@ -18,33 +18,23 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
1818 changes, the scale of the original figure is conserved. A
1919 function which restores the original values are returned.
2020 """
21- def no_op_apply_aspect (position = None ):
22- return
2321
2422 stack = contextlib .ExitStack ()
2523
2624 stack .callback (fig .set_tight_layout , fig .get_tight_layout ())
2725 fig .set_tight_layout (False )
2826
2927 for ax in fig .axes :
30- pos = ax .get_position (original = False ).frozen ()
31-
32- def _l (a , r , pos = pos ):
33- return pos
34-
3528 stack .callback (ax .set_axes_locator , ax .get_axes_locator ())
36- ax .set_axes_locator (_l )
37-
38- # override the method that enforces the aspect ratio
39- # on the Axes
40- stack .enter_context (_setattr_cm (ax , apply_aspect = no_op_apply_aspect ))
41-
42- if fixed_dpi is not None :
43- tr = Affine2D ().scale (fixed_dpi )
44- dpi_scale = fixed_dpi / fig .dpi
45- else :
46- tr = Affine2D ().scale (fig .dpi )
47- dpi_scale = 1.
29+ current_pos = ax .get_position (original = False ).frozen ()
30+ ax .set_axes_locator (lambda a , r , _pos = current_pos : _pos )
31+ # override the method that enforces the aspect ratio on the Axes
32+ stack .enter_context (_setattr_cm (ax , apply_aspect = lambda pos : None ))
33+
34+ if fixed_dpi is None :
35+ fixed_dpi = fig .dpi
36+ tr = Affine2D ().scale (fixed_dpi )
37+ dpi_scale = fixed_dpi / fig .dpi
4838
4939 _bbox = TransformedBbox (bbox_inches , tr )
5040
0 commit comments