From 3c2852855f377e716f6f0c9267ca8e0a1d8bcabd Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 13 Jan 2023 14:25:31 +0000 Subject: [PATCH] FIX: adjust_bbox should not modify layout engine --- lib/matplotlib/_tight_bbox.py | 3 --- lib/matplotlib/tests/test_figure.py | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/_tight_bbox.py b/lib/matplotlib/_tight_bbox.py index b2147b960735..e0fba389d120 100644 --- a/lib/matplotlib/_tight_bbox.py +++ b/lib/matplotlib/_tight_bbox.py @@ -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 = [] @@ -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) diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 065e0f728536..f3ece07660e3 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -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) == "
"