matplotlib._tight_layout#

Routines to adjust subplot params so that subplots arenicely fit in the figure. In doing so, only axis labels, tick labels, Axestitles and offsetboxes that are anchored to Axes are currently considered.

Internally, this module assumes that the margins (left margin, etc.) which aredifferences betweenAxes.get_tightbbox andAxes.bbox are independent ofAxes position. This may fail ifAxes.adjustable isdatalim as well assuch cases as when left or right margin are affected by xlabel.

matplotlib._tight_layout.get_subplotspec_list(axes_list,grid_spec=None)[source]#

Return a list of subplotspec from the given list of Axes.

For an instance of Axes that does not support subplotspec, None is insertedin the list.

If grid_spec is given, None is inserted for those not from the givengrid_spec.

matplotlib._tight_layout.get_tight_layout_figure(fig,axes_list,subplotspec_list,renderer,pad=1.08,h_pad=None,w_pad=None,rect=None)[source]#

Return subplot parameters for tight-layouted-figure with specified padding.

Parameters:
figFigure
axes_listlist of Axes
subplotspec_listlist ofSubplotSpec

The subplotspecs of each Axes.

rendererrenderer
padfloat

Padding between the figure edge and the edges of subplots, as afraction of the font size.

h_pad, w_padfloat

Padding (height/width) between edges of adjacent subplots. Defaults topad.

recttuple (left, bottom, right, top), default: None.

rectangle in normalized figure coordinatesthat the whole subplots area (including labels) will fit into.Defaults to using the entire figure.

Returns:
subplotspec or None

subplotspec kwargs to be passed toFigure.subplots_adjust orNone if tight_layout could not be accomplished.