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

Skip to content

Commit e93b150

Browse files
committed
FIX: adjust_bbox should not modify layout engine
1 parent a3011df commit e93b150

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/matplotlib/_tight_bbox.py

Lines changed: 0 additions & 3 deletions
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

Lines changed: 7 additions & 0 deletions
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)