Version 3.0.2
matplotlib
Fork me on GitHub

matplotlib.gridspec.SubplotSpec

class matplotlib.gridspec.SubplotSpec(gridspec, num1, num2=None)[source]

Bases: object

Specifies the location of the subplot in the given GridSpec.

The subplot will occupy the num1-th cell of the given gridspec. If num2 is provided, the subplot will span between num1-th cell and num2-th cell.

The index starts from 0.

get_geometry()[source]

Get the subplot geometry (n_rows, n_cols, start, stop).

start and stop are the index of the start and stop of the subplot.

get_gridspec()[source]
get_position(figure, return_all=False)[source]

Update the subplot position from figure.subplotpars.

get_rows_columns()[source]

Get the subplot row and column numbers: (n_rows, n_cols, row_start, row_stop, col_start, col_stop)

get_topmost_subplotspec()[source]

get the topmost SubplotSpec instance associated with the subplot

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

Return a GridSpecFromSubplotSpec that has this subplotspec as a parent.

Parameters:
nrows : int

Number of rows in grid.

ncols : int

Number or columns in grid.

Returns:
gridspec : GridSpec
Other Parameters:
**kwargs

All other parameters are passed to GridSpec.

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)
for i in range(3):
    fig.add_subplot(gssub[0, i])