Skip to content

Backport PR #29584 on branch v3.10.x (DOC: Recommend constrained_layout over tight_layout) #29691

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
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
10 changes: 6 additions & 4 deletions galleries/users_explain/axes/tight_layout_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
How to use tight-layout to fit plots within your figure cleanly.
.. tip::
*tight_layout* was the first layout engine in Matplotlib. The more modern
and more capable :ref:`Constrained Layout <constrainedlayout_guide>` should
typically be used instead.
*tight_layout* automatically adjusts subplot params so that the
subplot(s) fits in to the figure area. This is an experimental
feature and may not work for some cases. It only checks the extents
of ticklabels, axis labels, and titles.
An alternative to *tight_layout* is :ref:`constrained_layout
<constrainedlayout_guide>`.
Simple example
==============
Expand Down
11 changes: 8 additions & 3 deletions lib/matplotlib/layout_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
layout engine while the figure is being created. In particular, colorbars are
made differently with different layout engines (for historical reasons).

Matplotlib supplies two layout engines, `.TightLayoutEngine` and
`.ConstrainedLayoutEngine`. Third parties can create their own layout engine
by subclassing `.LayoutEngine`.
Matplotlib has two built-in layout engines:

- `.TightLayoutEngine` was the first layout engine added to Matplotlib.
See also :ref:`tight_layout_guide`.
- `.ConstrainedLayoutEngine` is more modern and generally gives better results.
See also :ref:`constrainedlayout_guide`.

Third parties can create their own layout engine by subclassing `.LayoutEngine`.
"""

from contextlib import nullcontext
Expand Down
Loading