Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ee34a9

Browse files
committed
MNT: be more careful about handling pre-monkey patched Axes
1 parent 910bfe5 commit 8ee34a9

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

lib/matplotlib/tight_bbox.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def no_op_apply_aspect(position=None):
2424
_boxout = fig.transFigure._boxout
2525

2626
fig.set_tight_layout(False)
27-
27+
old_aspect = []
2828
locator_list = []
29+
sentinel = object()
2930
for ax in fig.axes:
3031
pos = ax.get_position(original=False).frozen()
3132
locator_list.append(ax.get_axes_locator())
@@ -35,14 +36,21 @@ def _l(a, r, pos=pos):
3536
ax.set_axes_locator(_l)
3637
# override the method that enforces the aspect ratio
3738
# on the Axes
39+
if 'apply_aspect' in ax.__dict__:
40+
old_aspect.append(ax.apply_aspect)
41+
else:
42+
old_aspect.append(sentinel)
3843
ax.apply_aspect = no_op_apply_aspect
3944

4045
def restore_bbox():
41-
for ax, loc in zip(fig.axes, locator_list):
46+
for ax, loc, aspect in zip(fig.axes, locator_list, old_aspect):
4247
ax.set_axes_locator(loc)
43-
# delete our no-op function which un-hides the
44-
# original method
45-
del ax.apply_aspect
48+
if aspect is sentinel:
49+
# delete our no-op function which un-hides the
50+
# original method
51+
del ax.apply_aspect
52+
else:
53+
ax.apply_aspect = aspect
4654

4755
fig.bbox = origBbox
4856
fig.bbox_inches = origBboxInches

0 commit comments

Comments
 (0)