matplotlib.gridspec.GridSpec#
- classmatplotlib.gridspec.GridSpec(nrows,ncols,figure=None,left=None,bottom=None,right=None,top=None,wspace=None,hspace=None,width_ratios=None,height_ratios=None)[source]#
Bases:
GridSpecBase
A grid layout to place subplots within a figure.
The location of the grid cells is determined in a similar way to
SubplotParams
usingleft,right,top,bottom,wspaceandhspace.Indexing a GridSpec instance returns a
SubplotSpec
.- Parameters:
- nrows, ncolsint
The number of rows and columns of the grid.
- figure
Figure
, optional Only used for constrained layout to create a proper layoutgrid.
- left, right, top, bottomfloat, optional
Extent of the subplots as a fraction of figure width or height.Left cannot be larger than right, and bottom cannot be larger thantop. If not given, the values will be inferred from a figure orrcParams at draw time. See also
GridSpec.get_subplot_params
.- wspacefloat, optional
The amount of width reserved for space between subplots,expressed as a fraction of the average axis width.If not given, the values will be inferred from a figure orrcParams when necessary. See also
GridSpec.get_subplot_params
.- hspacefloat, optional
The amount of height reserved for space between subplots,expressed as a fraction of the average axis height.If not given, the values will be inferred from a figure orrcParams when necessary. See also
GridSpec.get_subplot_params
.- width_ratiosarray-like of lengthncols, optional
Defines the relative widths of the columns. Each column gets arelative width of
width_ratios[i]/sum(width_ratios)
.If not given, all columns will have the same width.- height_ratiosarray-like of lengthnrows, optional
Defines the relative heights of the rows. Each row gets arelative height of
height_ratios[i]/sum(height_ratios)
.If not given, all rows will have the same height.
- get_subplot_params(figure=None)[source]#
Return the
SubplotParams
for the GridSpec.In order of precedence the values are taken from
non-None attributes of the GridSpec
the providedfigure
Note that the
figure
attribute of the GridSpec is always ignored.
- locally_modified_subplot_params()[source]#
Return a list of the names of the subplot parameters explicitly setin the GridSpec.
This is a subset of the attributes of
SubplotParams
.
- tight_layout(figure,renderer=None,pad=1.08,h_pad=None,w_pad=None,rect=None)[source]#
Adjust subplot parameters to give specified padding.
- Parameters:
- figure
Figure
The figure.
- renderer
RendererBase
subclass, optional The renderer to be used.
- padfloat
Padding between the figure edge and the edges of subplots, as afraction of the font-size.
- h_pad, w_padfloat, optional
Padding (height/width) between edges of adjacent subplots.Defaults topad.
- recttuple (left, bottom, right, top), default: None
(left, bottom, right, top) rectangle in normalized figurecoordinates that the whole subplots area (including labels) willfit into. Default (None) is the whole figure.
- figure
- update(*,left=<UNSET>,bottom=<UNSET>,right=<UNSET>,top=<UNSET>,wspace=<UNSET>,hspace=<UNSET>)[source]#
Update the subplot parameters of the grid.
Parameters that are not explicitly given are not changed. Setting aparameter toNone resets it to
rcParams["figure.subplot.*"]
.- Parameters:
- left, right, top, bottomfloat or None, optional
Extent of the subplots as a fraction of figure width or height.
- wspace, hspacefloat or None, optional
Spacing between the subplots as a fraction of the average subplotwidth / height.