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

Skip to content

FIX: adjust_bbox should not modify layout engine #24971

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
merged 1 commit into from
Jan 13, 2023
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked before didn't it? It was when the rcParam was set that the problem was? Or was the layout still getting set to None, and then falling back to the rcParam?

Otherwise if this works, I'm all for it! I do wish all the context switching were simpler to debug, but...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On main this test throws an AttributeError because the layout engine got set to None. If we set the rcParam then we would get an assertion error on main. I'm happy to test either or both.

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