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

Skip to content

Commit a623149

Browse files
authored
Merge pull request matplotlib#11588 from jklymak/doc-warn-if-CL-plus-TL
DOC: warn if user is using constrained layout and uses subplots_adjust
2 parents 4fc9288 + 50fad1a commit a623149

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,12 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
20922092
*None*) and update the subplot locations.
20932093
20942094
"""
2095+
if self.get_constrained_layout():
2096+
self.set_constrained_layout(False)
2097+
warnings.warn("This figure was using constrained_layout==True, "
2098+
"but that is incompatible with subplots_adjust and "
2099+
"or tight_layout: setting "
2100+
"constrained_layout==False. ")
20952101
self.subplotpars.update(left, bottom, right, top, wspace, hspace)
20962102
for ax in self.axes:
20972103
if not isinstance(ax, SubplotBase):

lib/matplotlib/tests/test_figure.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ def test_figure_repr():
373373
assert repr(fig) == "<Figure size 100x200 with 0 Axes>"
374374

375375

376+
def test_warn_cl_plus_tl():
377+
fig, ax = plt.subplots(constrained_layout=True)
378+
with pytest.warns(UserWarning):
379+
# this should warn,
380+
fig.subplots_adjust(top=0.8)
381+
assert not(fig.get_constrained_layout())
382+
383+
376384
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python 3.6+")
377385
@pytest.mark.parametrize("fmt", ["png", "pdf", "ps", "eps", "svg"])
378386
def test_fspath(fmt, tmpdir):

0 commit comments

Comments
 (0)