matplotlib.gridspec.SubplotSpec#

classmatplotlib.gridspec.SubplotSpec(gridspec,num1,num2=None)[source]#

Bases:object

The location of a subplot in aGridSpec.

Note

Likely, you will never instantiate aSubplotSpec yourself. Instead,you will typically obtain one from aGridSpec using item-access.

Parameters:
gridspecGridSpec

The GridSpec, which the subplot is referencing.

num1, num2int

The subplot will occupy thenum1-th cell of the givengridspec. Ifnum2 is provided, the subplot will span betweennum1-th cell andnum2-th cellinclusive.

The index starts from 0.

propertycolspan#

The columns spanned by this subplot, as arange object.

get_geometry()[source]#

Return the subplot geometry as tuple(n_rows,n_cols,start,stop).

The indicesstart andstop define the range of the subplot withintheGridSpec.stop is inclusive (i.e. for a single cellstart==stop).

get_gridspec()[source]#
get_position(figure)[source]#

Update the subplot position fromfigure.subplotpars.

get_topmost_subplotspec()[source]#

Return the topmostSubplotSpec instance associated with the subplot.

is_first_col()[source]#
is_first_row()[source]#
is_last_col()[source]#
is_last_row()[source]#
propertynum2#
propertyrowspan#

The rows spanned by this subplot, as arange object.

subgridspec(nrows,ncols,**kwargs)[source]#

Create a GridSpec within this subplot.

The createdGridSpecFromSubplotSpec will have thisSubplotSpec asa parent.

Parameters:
nrowsint

Number of rows in grid.

ncolsint

Number of columns in grid.

Returns:
GridSpecFromSubplotSpec
Other Parameters:
**kwargs

All other parameters are passed toGridSpecFromSubplotSpec.

Examples

Adding three subplots in the space occupied by a single subplot:

fig=plt.figure()gs0=fig.add_gridspec(3,1)ax1=fig.add_subplot(gs0[0])ax2=fig.add_subplot(gs0[1])gssub=gs0[2].subgridspec(1,3)foriinrange(3):fig.add_subplot(gssub[0,i])

Examples usingmatplotlib.gridspec.SubplotSpec#

Nested GridSpecs

Nested GridSpecs

Arranging multiple Axes in a Figure

Arranging multiple Axes in a Figure

Constrained layout guide

Constrained layout guide