8000 DOC: warn if user is using constrained layout and use subplots_adjust by jklymak · Pull Request #11588 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

DOC: warn if user is using constrained layout and use subplots_adjust #11588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,12 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None,
*None*) and update the subplot locations.

"""
if self.get_constrained_layout():
self.set_constrained_layout(False)
warnings.warn("This figure was using constrained_layout==True, "
"but that is incompatible with subplots_adjust and "
"or tight_layout: setting "
"constrained_layout==False. ")
self.subplotpars.update(left, bottom, right, top, wspace, hspace)
for ax in self.axes:
if not isinstance(ax, SubplotBase):
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ def test_figure_repr():
assert repr(fig) == "<Figure size 100x200 with 0 Axes>"


def test_warn_cl_plus_tl():
fig, ax = plt.subplots(constrained_layout=True)
with pytest.warns(UserWarning):
# this should warn,
fig.subplots_adjust(top=0.8)
assert not(fig.get_constrained_layout())


@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python 3.6+")
@pytest.mark.parametrize("fmt", ["png", "pdf", "ps", "eps", "svg"])
def test_fspath(fmt, tmpdir):
Expand Down
0