pylupnt.utils.GridSpec

class pylupnt.utils.GridSpec(nrows, ncols, figure=None, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None, width_ratios=None, height_ratios=None)

A grid layout to place subplots within a figure.

The location of the grid cells is determined in a similar way to .SubplotParams using left, right, top, bottom, wspace and hspace.

Indexing a GridSpec instance returns a .SubplotSpec.

__init__(nrows, ncols, figure=None, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None, width_ratios=None, height_ratios=None)
Parameters:
  • nrows (int) – The number of rows and columns of the grid.

  • ncols (int) – The number of rows and columns of the grid.

  • figure (.Figure, optional) – Only used for constrained layout to create a proper layoutgrid.

  • left (float, optional) – Extent of the subplots as a fraction of figure width or height. Left cannot be larger than right, and bottom cannot be larger than top. If not given, the values will be inferred from a figure or rcParams at draw time. See also GridSpec.get_subplot_params.

  • right (float, optional) – Extent of the subplots as a fraction of figure width or height. Left cannot be larger than right, and bottom cannot be larger than top. If not given, the values will be inferred from a figure or rcParams at draw time. See also GridSpec.get_subplot_params.

  • top (float, optional) – Extent of the subplots as a fraction of figure width or height. Left cannot be larger than right, and bottom cannot be larger than top. If not given, the values will be inferred from a figure or rcParams at draw time. See also GridSpec.get_subplot_params.

  • bottom (float, optional) – Extent of the subplots as a fraction of figure width or height. Left cannot be larger than right, and bottom cannot be larger than top. If not given, the values will be inferred from a figure or rcParams at draw time. See also GridSpec.get_subplot_params.

  • wspace (float, optional) – The amount of width reserved for space between subplots, expressed as a fraction of the average axis width. If not given, the values will be inferred from a figure or rcParams when necessary. See also GridSpec.get_subplot_params.

  • hspace (float, optional) – The amount of height reserved for space between subplots, expressed as a fraction of the average axis height. If not given, the values will be inferred from a figure or rcParams when necessary. See also GridSpec.get_subplot_params.

  • width_ratios (array-like of length ncols, optional) – Defines the relative widths of the columns. Each column gets a relative width of width_ratios[i] / sum(width_ratios). If not given, all columns will have the same width.

  • height_ratios (array-like of length nrows, optional) – Defines the relative heights of the rows. Each row gets a relative height of height_ratios[i] / sum(height_ratios). If not given, all rows will have the same height.

get_geometry()

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

get_grid_positions(fig)

Return the positions of the grid cells in figure coordinates.

Parameters:

fig (~matplotlib.figure.Figure) – The figure the grid should be applied to. The subplot parameters (margins and spacing between subplots) are taken from fig.

Returns:

bottoms, tops, lefts, rights – The bottom, top, left, right positions of the grid cells in figure coordinates.

Return type:

array

get_height_ratios()

Return the height ratios.

This is None if no height ratios have been set explicitly.

get_subplot_params(figure=None)

Return the .SubplotParams for the GridSpec.

In order of precedence the values are taken from

Note that the figure attribute of the GridSpec is always ignored.

get_width_ratios()

Return the width ratios.

This is None if no width ratios have been set explicitly.

locally_modified_subplot_params()

Return a list of the names of the subplot parameters explicitly set in the GridSpec.

This is a subset of the attributes of .SubplotParams.

new_subplotspec(loc, rowspan=1, colspan=1)

Create and return a .SubplotSpec instance.

Parameters:
  • loc ((int, int)) – The position of the subplot in the grid as (row_index, column_index).

  • rowspan (int, default: 1) – The number of rows and columns the subplot should span in the grid.

  • colspan (int, default: 1) – The number of rows and columns the subplot should span in the grid.

set_height_ratios(height_ratios)

Set the relative heights of the rows.

height_ratios must be of length nrows. Each row gets a relative height of height_ratios[i] / sum(height_ratios).

set_width_ratios(width_ratios)

Set the relative widths of the columns.

width_ratios must be of length ncols. Each column gets a relative width of width_ratios[i] / sum(width_ratios).

subplots(*, sharex=False, sharey=False, squeeze=True, subplot_kw=None)

Add all subplots specified by this GridSpec to its parent figure.

See .Figure.subplots for detailed documentation.

tight_layout(figure, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None)

Adjust subplot parameters to give specified padding.

Parameters:
  • figure (.Figure) – The figure.

  • renderer (.RendererBase subclass, optional) – The renderer to be used.

  • pad (float) – Padding between the figure edge and the edges of subplots, as a fraction of the font-size.

  • h_pad (float, optional) – Padding (height/width) between edges of adjacent subplots. Defaults to pad.

  • w_pad (float, optional) – Padding (height/width) between edges of adjacent subplots. Defaults to pad.

  • rect (tuple (left, bottom, right, top), default: None) – (left, bottom, right, top) rectangle in normalized figure coordinates that the whole subplots area (including labels) will fit into. Default (None) is the whole figure.

update(**kwargs)

Update the subplot parameters of the grid.

Parameters that are not explicitly given are not changed. Setting a parameter to None resets it to :rc:`figure.subplot.*`.

Parameters:
  • left (float or None, optional) – Extent of the subplots as a fraction of figure width or height.

  • right (float or None, optional) – Extent of the subplots as a fraction of figure width or height.

  • top (float or None, optional) – Extent of the subplots as a fraction of figure width or height.

  • bottom (float or None, optional) – Extent of the subplots as a fraction of figure width or height.

  • wspace (float, optional) – Spacing between the subplots as a fraction of the average subplot width / height.

  • hspace (float, optional) – Spacing between the subplots as a fraction of the average subplot width / height.

property ncols

The number of columns in the grid.

property nrows

The number of rows in the grid.