Skip to content

Commit 235b01f

Browse files
authored
Merge pull request matplotlib#24971 from rcomer/adjust_bbox-layout-engine
FIX: adjust_bbox should not modify layout engine
2 parents 90fe9e0 + 3c28528 commit 235b01f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/matplotlib/_tight_bbox.py

-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
1717
"""
1818
origBbox = fig.bbox
1919
origBboxInches = fig.bbox_inches
20-
orig_layout = fig.get_layout_engine()
21-
fig.set_layout_engine(None)
2220
_boxout = fig.transFigure._boxout
2321

2422
old_aspect = []
@@ -46,7 +44,6 @@ def restore_bbox():
4644

4745
fig.bbox = origBbox
4846
fig.bbox_inches = origBboxInches
49-
fig.set_layout_engine(orig_layout)
5047
fig.transFigure._boxout = _boxout
5148
fig.transFigure.invalidate()
5249
fig.patch.set_bounds(0, 0, 1, 1)

lib/matplotlib/tests/test_figure.py

+7
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,13 @@ def test_savefig_pixel_ratio(backend):
532532
assert ratio1 == ratio2
533533

534534

535+
def test_savefig_preserve_layout_engine(tmp_path):
536+
fig = plt.figure(layout='compressed')
537+
fig.savefig(tmp_path / 'foo.png', bbox_inches='tight')
538+
539+
assert fig.get_layout_engine()._compress
540+
541+
535542
def test_figure_repr():
536543
fig = plt.figure(figsize=(10, 20), dpi=10)
537544
assert repr(fig) == "<Figure size 100x200 with 0 Axes>"

0 commit comments

Comments
 (0)