From 009415f3ebe1087f13a0acfda02734874b1e8d39 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 5 Apr 2023 09:32:34 -0400 Subject: [PATCH 1/2] FIX: correctly unset the layout engine in Figure.tight_layout closes #7805 --- lib/matplotlib/figure.py | 2 +- lib/matplotlib/tests/test_figure.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 926944e5a577..32c5388592d0 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3515,7 +3515,7 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): and previous_engine is not None: _api.warn_external('The figure layout has changed to tight') finally: - self.set_layout_engine(None) + self.set_layout_engine('none') def figaspect(arg): diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index d8b06003cd00..64477f4e216a 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -659,6 +659,15 @@ def test_invalid_layouts(): fig.set_layout_engine("constrained") +@check_figures_equal(extensions=["png"]) +def test_tightlayout_autolayout_deconfilct(fig_test, fig_ref): + for fig, autolayout in zip([fig_ref, fig_test], [False, True]): + with mpl.rc_context({'figure.autolayout': autolayout}): + axes = fig.subplots(ncols=2) + fig.tight_layout(w_pad=10) + assert isinstance(fig.get_layout_engine(), PlaceHolderLayoutEngine) + + @pytest.mark.parametrize('layout', ['constrained', 'compressed']) def test_layout_change_warning(layout): """ From 02014be44efa100f6b345c453de8834b59dacc5c Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 5 Apr 2023 09:44:06 -0400 Subject: [PATCH 2/2] MNT: fix typo in test name Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com> --- lib/matplotlib/tests/test_figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 64477f4e216a..4188ca878fed 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -660,7 +660,7 @@ def test_invalid_layouts(): @check_figures_equal(extensions=["png"]) -def test_tightlayout_autolayout_deconfilct(fig_test, fig_ref): +def test_tightlayout_autolayout_deconflict(fig_test, fig_ref): for fig, autolayout in zip([fig_ref, fig_test], [False, True]): with mpl.rc_context({'figure.autolayout': autolayout}): axes = fig.subplots(ncols=2)