From 50cad2a347ff0beb4e2d322b6d54ff4cc650348f Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Fri, 28 Feb 2025 12:51:08 +0100 Subject: [PATCH] Backport PR #29584: DOC: Recommend constrained_layout over tight_layout --- galleries/users_explain/axes/tight_layout_guide.py | 10 ++++++---- lib/matplotlib/layout_engine.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/galleries/users_explain/axes/tight_layout_guide.py b/galleries/users_explain/axes/tight_layout_guide.py index 455bb57de126..672704bb9726 100644 --- a/galleries/users_explain/axes/tight_layout_guide.py +++ b/galleries/users_explain/axes/tight_layout_guide.py @@ -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 ` 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 -`. - - Simple example ============== diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index 5a96745d0697..8a3276b53371 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -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