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

Skip to content

Commit 648a04e

Browse files
committed
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 Conflicts: lib/matplotlib/figure.py - signature on master has changed to explicit kwargs, conflict due to that change.
1 parent 86a3bac commit 648a04e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,14 @@ def subplots_adjust(self, *args, **kwargs):
20902090
*None*) and update the subplot locations.
20912091
20922092
"""
2093+
if self.get_constrained_layout():
2094+
self.set_constrained_layout(False)
2095+
warnings.warn("This figure was using constrained_layout==True, "
2096+
"but that is incompatible with subplots_adjust and "
2097+
"or tight_layout: setting "
2098+
"constrained_layout==False. ")
20932099
self.subplotpars.update(*args, **kwargs)
2100+
20942101
for ax in self.axes:
20952102
if not isinstance(ax, SubplotBase):
20962103
# Check if sharing a subplots axis

lib/matplotlib/tests/test_figure.py

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

378378

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

0 commit comments

Comments
 (0)