Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1133d85

Browse files
committed
BUG: Warn when an existing layout manager changes to tight layout
1 parent8d2d4c2 commit1133d85

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎lib/matplotlib/figure.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,10 @@ def _check_layout_engines_compat(self, old, new):
25062506
"""
25072507
ifoldisNoneornewisNone:
25082508
returnTrue
2509+
ifisinstance(old,ConstrainedLayoutEngine) \
2510+
andisinstance(new,TightLayoutEngine):
2511+
_api.warn_external("The layout manager has been changed to "
2512+
"'tight'.")
25092513
ifold.colorbar_gridspec==new.colorbar_gridspec:
25102514
returnTrue
25112515
# colorbar layout different, so check if any colorbars are on the

‎lib/matplotlib/tests/test_figure.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ def test_invalid_layouts():
571571

572572
# test that layouts can be swapped if no colorbar:
573573
fig,ax=plt.subplots(layout="constrained")
574-
fig.set_layout_engine("tight")
574+
withpytest.warns(UserWarning):
575+
fig.set_layout_engine("tight")
575576
assertisinstance(fig.get_layout_engine(),TightLayoutEngine)
576577
fig.set_layout_engine("constrained")
577578
assertisinstance(fig.get_layout_engine(),ConstrainedLayoutEngine)
@@ -581,7 +582,8 @@ def test_invalid_layouts():
581582
pc=ax.pcolormesh(np.random.randn(2,2))
582583
fig.colorbar(pc)
583584
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
584-
fig.set_layout_engine("tight")
585+
withpytest.warns(UserWarning):
586+
fig.set_layout_engine("tight")
585587
fig.set_layout_engine("none")
586588
withpytest.raises(RuntimeError,match='Colorbar layout of new layout'):
587589
fig.set_layout_engine("tight")
@@ -598,6 +600,14 @@ def test_invalid_layouts():
598600
fig.set_layout_engine("constrained")
599601

600602

603+
deftest_layout_change_warning():
604+
"""Raise a warning when an existing layout manager is changed to tight."""
605+
forlayoutin ('constrained','compressed'):
606+
fig,ax=plt.subplots(layout=layout)
607+
withpytest.warns(UserWarning,match='The layout manager has been'):
608+
plt.tight_layout()
609+
610+
601611
@check_figures_equal(extensions=["png","pdf"])
602612
deftest_add_artist(fig_test,fig_ref):
603613
fig_test.dpi=100

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp