Skip to content

Backport PR #25624 on branch v3.7.x (FIX: correctly unset the layout engine in Figure.tight_layout) #25626

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
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
2 changes: 1 addition & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3512,7 +3512,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):
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,15 @@ def test_invalid_layouts():
fig.set_layout_engine("constrained")


@check_figures_equal(extensions=["png"])
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)
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):
"""
Expand Down