matplotlib.gridspec.SubplotSpec

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

Bases: object

Specifies the location of a subplot in a GridSpec.

Note

Likely, you'll never instantiate a SubplotSpec yourself. Instead you will typically obtain one from a GridSpec using item-access.

Parameters:
gridspecGridSpec

The GridSpec, which the subplot is referencing.

num1, num2int

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 inclusive.

The index starts from 0.

__dict__ = mappingproxy({'__module__': 'matplotlib.gridspec', '__doc__': "\n Specifies the location of a subplot in a `GridSpec`.\n\n .. note::\n\n Likely, you'll never instantiate a `SubplotSpec` yourself. Instead you\n will typically obtain one from a `GridSpec` using item-access.\n\n Parameters\n ----------\n gridspec : `~matplotlib.gridspec.GridSpec`\n The GridSpec, which the subplot is referencing.\n num1, num2 : int\n The subplot will occupy the num1-th cell of the given\n gridspec. If num2 is provided, the subplot will span between\n num1-th cell and num2-th cell *inclusive*.\n\n The index starts from 0.\n ", '__init__': <function SubplotSpec.__init__>, '__repr__': <function SubplotSpec.__repr__>, '_from_subplot_args': <staticmethod object>, 'num2': <property object>, '__getstate__': <function SubplotSpec.__getstate__>, 'get_gridspec': <function SubplotSpec.get_gridspec>, 'get_geometry': <function SubplotSpec.get_geometry>, 'get_rows_columns': <function SubplotSpec.get_rows_columns>, 'rowspan': <property object>, 'colspan': <property object>, 'get_position': <function SubplotSpec.get_position>, 'get_topmost_subplotspec': <function SubplotSpec.get_topmost_subplotspec>, '__eq__': <function SubplotSpec.__eq__>, '__hash__': <function SubplotSpec.__hash__>, 'subgridspec': <function SubplotSpec.subgridspec>, '__dict__': <attribute '__dict__' of 'SubplotSpec' objects>, '__weakref__': <attribute '__weakref__' of 'SubplotSpec' objects>, '__annotations__': {}})
__eq__(other)[source]

Two SubplotSpecs are considered equal if they refer to the same position(s) in the same GridSpec.

__getstate__()[source]
__hash__()[source]

Return hash(self).

__init__(gridspec, num1, num2=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'matplotlib.gridspec'
__repr__()[source]

Return repr(self).

__weakref__

list of weak references to the object (if defined)

property colspan

The columns spanned by this subplot, as a range object.

get_geometry()[source]

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

The indices start and stop define the range of the subplot within the GridSpec. stop is inclusive (i.e. for a single cell start == stop).

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

Update the subplot position from figure.subplotpars.

get_rows_columns()[source]

[Deprecated] Return the subplot row and column numbers as a tuple (n_rows, n_cols, row_start, row_stop, col_start, col_stop).

Notes

Deprecated since version 3.3.

get_topmost_subplotspec()[source]

Return the topmost SubplotSpec instance associated with the subplot.

property num2
property rowspan

The rows spanned by this subplot, as a range object.

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

Create a GridSpec within this subplot.

The created GridSpecFromSubplotSpec will have this SubplotSpec as a parent.

Parameters:
nrowsint

Number of rows in grid.

ncolsint

Number or columns in grid.

Returns:
GridSpecFromSubplotSpec
Other Parameters:
**kwargs

All other parameters are passed to GridSpecFromSubplotSpec.

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])