API reference
Layout Engine
- class mpl_direct_layout.DirectLayoutEngine(*, h_pad=None, w_pad=None, rect=(0, 0, 1, 1), left=None, right=None, top=None, bottom=None, suptitle_pad=None, **kwargs)[source]
Bases:
LayoutEngineA layout engine that uses direct equation solving instead of kiwisolver.
Positions axes on a grid by measuring decoration sizes (tick labels, axis labels, titles, colorbars) and solving for positions algebraically.
Usage:
import mpl_direct_layout import matplotlib.pyplot as plt fig, axs = plt.subplots(2, 2, layout='direct')
Or explicitly:
fig = plt.figure() fig.set_layout_engine('direct') axs = fig.subplots(2, 2)
- Parameters:
h_pad (float) – Padding between axes in inches. Defaults to 3 points (3/72 ≈ 0.042 in).
w_pad (float) – Padding between axes in inches. Defaults to 3 points (3/72 ≈ 0.042 in).
rect (tuple of 4 floats) – Rectangle
(left, bottom, width, height)in figure coordinates (each 0–1) within which to perform layout.left (float, optional) – Fixed outer margins in inches from the figure edges. Defaults: 6 points (6/72 ≈ 0.083 in) on all sides.
right (float, optional) – Fixed outer margins in inches from the figure edges. Defaults: 6 points (6/72 ≈ 0.083 in) on all sides.
top (float, optional) – Fixed outer margins in inches from the figure edges. Defaults: 6 points (6/72 ≈ 0.083 in) on all sides.
bottom (float, optional) – Fixed outer margins in inches from the figure edges. Defaults: 6 points (6/72 ≈ 0.083 in) on all sides.
suptitle_pad (float, optional) – Gap in inches between suptitle / supxlabel / supylabel and the axes content. Default: 0.1 in.
- set(*, h_pad=None, w_pad=None, rect=None, left=None, right=None, top=None, bottom=None, suptitle_pad=None)[source]
Set layout parameters.
- Parameters:
h_pad (float) – Padding between axes in inches.
w_pad (float) – Padding between axes in inches.
rect (tuple of 4 floats) –
(left, bottom, width, height)layout rectangle in figure coords.left (float) – Outer margins in inches from figure edges.
right (float) – Outer margins in inches from figure edges.
top (float) – Outer margins in inches from figure edges.
bottom (float) – Outer margins in inches from figure edges.
suptitle_pad (float) – Gap in inches between suptitle/supxlabel/supylabel and axes.
- property adjust_compatible
Return a boolean if the layout engine is compatible with ~.Figure.subplots_adjust.
- property colorbar_gridspec
Return a boolean if the layout engine creates colorbars using a gridspec.
- get()
Return copy of the parameters for the layout engine.