matplotlib

Table Of Contents

Previous topic

matplotlib font_manager

Next topic

matplotlib mathtext

This Page

matplotlib gridspec

matplotlib.gridspec

gridspec is a module which specifies the location of the subplot in the figure.

GridSpec
specifies the geometry of the grid that a subplot will be placed. The number of rows and number of columns of the grid need to be set. Optionally, the subplot layout parameters (e.g., left, right, etc.) can be tuned.
SubplotSpec
specifies the location of the subplot in the given GridSpec.
class matplotlib.gridspec.GridSpec(nrows, ncols, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None, width_ratios=None, height_ratios=None)

Bases: matplotlib.gridspec.GridSpecBase

A class that specifies the geometry of the grid that a subplot will be placed. The location of grid is determined by similar way as the SubplotParams.

The number of rows and number of columns of the grid need to be set. Optionally, the subplot layout parameters (e.g., left, right, etc.) can be tuned.

get_subplot_params(fig=None)

return a dictionary of subplot layout parameters. The default parameters are from rcParams unless a figure attribute is set.

update(**kwargs)

Update the current values. If any kwarg is None, default to the current value, if set, otherwise to rc.

class matplotlib.gridspec.GridSpecBase(nrows, ncols, height_ratios=None, width_ratios=None)

Bases: object

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

The number of rows and number of columns of the grid need to be set. Optionally, the ratio of heights and widths of ros and columns can be specified.

get_geometry()

get the geometry of the grid, eg 2,3

get_grid_positions(fig)

return lists of bottom and top position of rows, left and right positions of columns.

get_height_ratios()
get_subplot_params(fig=None)
get_width_ratios()
new_subplotspec(loc, rowspan=1, colspan=1)

create and return a SuplotSpec instance.

set_height_ratios(height_ratios)
set_width_ratios(width_ratios)
class matplotlib.gridspec.GridSpecFromSubplotSpec(nrows, ncols, subplot_spec, wspace=None, hspace=None, height_ratios=None, width_ratios=None)

Bases: matplotlib.gridspec.GridSpecBase

GridSpec whose subplot layout parameters are inherited from the location specified by a given SubplotSpec.

The number of rows and number of columns of the grid need to be set. An instance of SubplotSpec is also needed to be set from which the layout parameters will be inheirted. The wspace and hspace of the layout can be optionally specified or the default values (from the figure or rcParams) will be used.

get_subplot_params(fig=None)

return a dictionary of subplot layout parameters.

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

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 stars from 0.

get_geometry()

get the subplot geometry, eg 2,2,3. Unlike SuplorParams, index is 0-based

get_gridspec()
get_position(fig, return_all=False)

update the subplot position from fig.subplotpars