matplotlib.gridspec.GridSpecBase#

classmatplotlib.gridspec.GridSpecBase(nrows,ncols,height_ratios=None,width_ratios=None)[source]#

Bases:object

A base class of GridSpec that specifies the geometry of the gridthat a subplot will be placed.

Parameters:
nrows, ncolsint

The number of rows and columns of the grid.

width_ratiosarray-like of lengthncols, optional

Defines the relative widths of the columns. Each column gets arelative width ofwidth_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 ofheight_ratios[i]/sum(height_ratios).If not given, all rows will have the same height.

get_geometry()[source]#

Return a tuple containing the number of rows and columns in the grid.

get_grid_positions(fig)[source]#

Return the positions of the grid cells in figure coordinates.

Parameters:
figFigure

The figure the grid should be applied to. The subplot parameters(margins and spacing between subplots) are taken fromfig.

Returns:
bottoms, tops, lefts, rightsarray

The bottom, top, left, right positions of the grid cells infigure coordinates.

get_height_ratios()[source]#

Return the height ratios.

This isNone if no height ratios have been set explicitly.

get_subplot_params(figure=None)[source]#
get_width_ratios()[source]#

Return the width ratios.

This isNone if no width ratios have been set explicitly.

propertyncols#

The number of columns in the grid.

new_subplotspec(loc,rowspan=1,colspan=1)[source]#

Create and return aSubplotSpec instance.

Parameters:
loc(int, int)

The position of the subplot in the grid as(row_index,column_index).

rowspan, colspanint, default: 1

The number of rows and columns the subplot should span in the grid.

propertynrows#

The number of rows in the grid.

set_height_ratios(height_ratios)[source]#

Set the relative heights of the rows.

height_ratios must be of lengthnrows. Each row gets a relativeheight ofheight_ratios[i]/sum(height_ratios).

set_width_ratios(width_ratios)[source]#

Set the relative widths of the columns.

width_ratios must be of lengthncols. Each column gets a relativewidth ofwidth_ratios[i]/sum(width_ratios).

subplots(*,sharex=False,sharey=False,squeeze=True,subplot_kw=None)[source]#

Add all subplots specified by thisGridSpec to its parent figure.

SeeFigure.subplots for detailed documentation.

Examples usingmatplotlib.gridspec.GridSpecBase#

Resize Axes with constrained layout

Resize Axes with constrained layout

GridSpec with variable sizes and spacing

GridSpec with variable sizes and spacing

Gridspec for multi-column/row subplot layouts

Gridspec for multi-column/row subplot layouts

Nested Gridspecs

Nested Gridspecs

Positioning and orientation of imshow images

Positioning and orientation of imshow images

Constrained layout guide

Constrained layout guide

Tight layout guide

Tight layout guide