@@ -18,33 +18,23 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
18
18
changes, the scale of the original figure is conserved. A
19
19
function which restores the original values are returned.
20
20
"""
21
- def no_op_apply_aspect (position = None ):
22
- return
23
21
24
22
stack = contextlib .ExitStack ()
25
23
26
24
stack .callback (fig .set_tight_layout , fig .get_tight_layout ())
27
25
fig .set_tight_layout (False )
28
26
29
27
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
-
35
28
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
48
38
49
39
_bbox = TransformedBbox (bbox_inches , tr )
50
40
0 commit comments