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

Appearance settings

Commit 50fad1a

Browse filesBrowse files
committed
DOC: warn if user is using constrained layout and tries to use subplots_adjust
1 parent 5dc51e0 commit 50fad1a
Copy full SHA for 50fad1a

File tree

Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+6Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.