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

Skip to content

Commit 6a82f38

Browse files
oscargusmeeseeksmachine
authored andcommitted
Backport PR #25624: FIX: correctly unset the layout engine in Figure.tight_layout
1 parent 5ac2113 commit 6a82f38

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3512,7 +3512,7 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None):
35123512
and previous_engine is not None:
35133513
_api.warn_external('The figure layout has changed to tight')
35143514
finally:
3515-
self.set_layout_engine(None)
3515+
self.set_layout_engine('none')
35163516

35173517

35183518
def figaspect(arg):

lib/matplotlib/tests/test_figure.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,15 @@ def test_invalid_layouts():
621621
fig.set_layout_engine("constrained")
622622

623623

624+
@check_figures_equal(extensions=["png"])
625+
def test_tightlayout_autolayout_deconflict(fig_test, fig_ref):
626+
for fig, autolayout in zip([fig_ref, fig_test], [False, True]):
627+
with mpl.rc_context({'figure.autolayout': autolayout}):
628+
axes = fig.subplots(ncols=2)
629+
fig.tight_layout(w_pad=10)
630+
assert isinstance(fig.get_layout_engine(), PlaceHolderLayoutEngine)
631+
632+
624633
@pytest.mark.parametrize('layout', ['constrained', 'compressed'])
625634
def test_layout_change_warning(layout):
626635
"""

0 commit comments

Comments
 (0)