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

Skip to content

Backport PR #24971 on branch v3.7.x (FIX: adjust_bbox should not modify layout engine) #24975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/matplotlib/_tight_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
"""
origBbox = fig.bbox
origBboxInches = fig.bbox_inches
orig_layout = fig.get_layout_engine()
fig.set_layout_engine(None)
_boxout = fig.transFigure._boxout

old_aspect = []
Expand Down Expand Up @@ -46,7 +44,6 @@ def restore_bbox():

fig.bbox = origBbox
fig.bbox_inches = origBboxInches
fig.set_layout_engine(orig_layout)
fig.transFigure._boxout = _boxout
fig.transFigure.invalidate()
fig.patch.set_bounds(0, 0, 1, 1)
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ def test_savefig_pixel_ratio(backend):
assert ratio1 == ratio2


def test_savefig_preserve_layout_engine(tmp_path):
fig = plt.figure(layout='compressed')
fig.savefig(tmp_path / 'foo.png', bbox_inches='tight')

assert fig.get_layout_engine()._compress


def test_figure_repr():
fig = plt.figure(figsize=(10, 20), dpi=10)
assert repr(fig) == "<Figure size 100x200 with 0 Axes>"
Expand Down