Skip to content

Commit afbe5bb

Browse files
committed
ENH: implement and use base layout_engine for more flexible layout.
1 parent ad95791 commit afbe5bb

12 files changed

+461
-202
lines changed

doc/api/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Alphabetical list of modules:
6666
fontconfig_pattern_api.rst
6767
gridspec_api.rst
6868
image_api.rst
69+
layout_engine_api.rst
6970
legend_api.rst
7071
legend_handler_api.rst
7172
lines_api.rst

doc/api/layout_engine_api.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
****************************
2+
``matplotlib.layout_engine``
3+
****************************
4+
5+
.. currentmodule:: matplotlib.layout_engine
6+
7+
.. automodule:: matplotlib.layout_engine
8+
:members:
9+
:inherited-members:

lib/matplotlib/_constrained_layout.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import numpy as np
1919

2020
from matplotlib import _api, artist as martist
21+
from matplotlib.backend_bases import _get_renderer
2122
import matplotlib.transforms as mtransforms
2223
import matplotlib._layoutgrid as mlayoutgrid
2324

@@ -62,7 +63,7 @@
6263

6364

6465
######################################################
65-
def do_constrained_layout(fig, renderer, h_pad, w_pad,
66+
def do_constrained_layout(fig, h_pad, w_pad,
6667
hspace=None, wspace=None):
6768
"""
6869
Do the constrained_layout. Called at draw time in
@@ -91,6 +92,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
9192
layoutgrid : private debugging structure
9293
"""
9394

95+
renderer = _get_renderer(fig)
9496
# make layoutgrid tree...
9597
layoutgrids = make_layoutgrids(fig, None)
9698
if not layoutgrids['hasgrids']:

lib/matplotlib/backend_bases.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ def print_figure(
22712271
if bbox_inches is None:
22722272
bbox_inches = rcParams['savefig.bbox']
22732273

2274-
if (self.figure.get_constrained_layout() or
2274+
if (self.figure.get_layout_engine() is not None or
22752275
bbox_inches == "tight"):
22762276
# we need to trigger a draw before printing to make sure
22772277
# CL works. "tight" also needs a draw to get the right
@@ -2300,8 +2300,8 @@ def print_figure(
23002300
else:
23012301
_bbox_inches_restore = None
23022302

2303-
# we have already done CL above, so turn it off:
2304-
stack.enter_context(self.figure._cm_set(constrained_layout=False))
2303+
# we have already done layout above, so turn it off:
2304+
stack.enter_context(self.figure._cm_set(layout_engine=None))
23052305
try:
23062306
# _get_renderer may change the figure dpi (as vector formats
23072307
# force the figure dpi to 72), so we need to set it again here.

0 commit comments

Comments
 (0)