ENH: Layout engine by jklymak · Pull Request #20426 · matplotlib/matplotlib · GitHub
Skip to content
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
1 change: 1 addition & 0 deletions doc/api/index.rst
9 changes: 9 additions & 0 deletions doc/api/layout_engine_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
****************************
``matplotlib.layout_engine``
****************************

.. currentmodule:: matplotlib.layout_engine

.. automodule:: matplotlib.layout_engine
:members:
:inherited-members:
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/20426-JK.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Incompatible layout engines raise
---------------------------------
``tight_layout`` and ``constrained_layout`` are incompatible if
a colorbar has been added to the figure. Invoking the incompatible layout
engine used to warn, but now raises with a ``RuntimeError``.
7 changes: 7 additions & 0 deletions doc/users/next_whats_new/layout_engine.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
New ``layout_engine`` module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matplotlib ships with ``tight_layout`` and ``constrained_layout`` layout
engines. A new ``layout_engine`` module is provided to allow downstream
libraries to write their own layout engines and `~.figure.Figure` objects can
now take a `.LayoutEngine` subclass as an argument to the *layout* parameter.
4 changes: 3 additions & 1 deletion lib/matplotlib/_constrained_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np

from matplotlib import _api, artist as martist
from matplotlib.backend_bases import _get_renderer
import matplotlib.transforms as mtransforms
import matplotlib._layoutgrid as mlayoutgrid

Expand Down Expand Up @@ -62,7 +63,7 @@


######################################################
def do_constrained_layout(fig, renderer, h_pad, w_pad,
def do_constrained_layout(fig, h_pad, w_pad,
hspace=None, wspace=None):
"""
Do the constrained_layout. Called at draw time in
Expand Down Expand Up @@ -91,6 +92,7 @@ def do_constrained_layout(fig, renderer, h_pad, w_pad,
layoutgrid : private debugging structure
"""

renderer = _get_renderer(fig)
# make layoutgrid tree...
layoutgrids = make_layoutgrids(fig, None)
if not layoutgrids['hasgrids']:
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/_tight_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ def adjust_bbox(fig, bbox_inches, fixed_dpi=None):
"""
origBbox = fig.bbox
origBboxInches = fig.bbox_inches
orig_tight_layout = fig.get_tight_layout()
orig_layout = fig.get_layout_engine()
fig.set_layout_engine(None)
_boxout = fig.transFigure._boxout

fig.set_tight_layout(False)

old_aspect = []
locator_list = []
sentinel = object()
Expand All @@ -47,7 +46,7 @@ def restore_bbox():

fig.bbox = origBbox
fig.bbox_inches = origBboxInches
fig.set_tight_layout(orig_tight_layout)
fig.set_layout_engine(orig_layout)
fig.transFigure._boxout = _boxout
fig.transFigure.invalidate()
fig.patch.set_bounds(0, 0, 1, 1)
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backend_bases.py
Loading