From 3e5788a5160f53268033195e74d88a443b56be43 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:33:23 +0100 Subject: [PATCH 1/3] DOC: Recommend constrained_layout over tight_layout Closes #17339 by addressing the remaining open issue https://github.com/matplotlib/matplotlib/issues/17339#issuecomment-625516913. --- 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 dcffa7437b94..6a981ce49330 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..87d920c51660 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 two 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 From 9eac770c8e478d0aee11c951bb3bd36b27e591c0 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:07:58 +0100 Subject: [PATCH 2/3] Update lib/matplotlib/layout_engine.py Co-authored-by: Mecanerd --- lib/matplotlib/layout_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/layout_engine.py b/lib/matplotlib/layout_engine.py index 87d920c51660..8a3276b53371 100644 --- a/lib/matplotlib/layout_engine.py +++ b/lib/matplotlib/layout_engine.py @@ -10,7 +10,7 @@ layout engine while the figure is being created. In particular, colorbars are made differently with different layout engines (for historical reasons). -Matplotlib has two built-in two layout engines: +Matplotlib has two built-in layout engines: - `.TightLayoutEngine` was the first layout engine added to Matplotlib. See also :ref:`tight_layout_guide`. From 665dd5cbf38bff212ebcad4f6f6297e6ff96f66b Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:54:22 +0100 Subject: [PATCH 3/3] Update galleries/users_explain/axes/tight_layout_guide.py Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com> --- galleries/users_explain/axes/tight_layout_guide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galleries/users_explain/axes/tight_layout_guide.py b/galleries/users_explain/axes/tight_layout_guide.py index 6a981ce49330..c0040ec1a8c8 100644 --- a/galleries/users_explain/axes/tight_layout_guide.py +++ b/galleries/users_explain/axes/tight_layout_guide.py @@ -12,7 +12,7 @@ .. tip:: *tight_layout* was the first layout engine in Matplotlib. The more modern - and more capable :ref:`constrained_layout ` should + and more capable :ref:`Constrained Layout ` should typically be used instead. *tight_layout* automatically adjusts subplot params so that the