nested_grid_plotter.SubplotsMosaicBuilder#

class nested_grid_plotter.SubplotsMosaicBuilder(mosaic, *, sharex: bool = False, sharey: bool = False, width_ratios: ArrayLike | None = None, height_ratios: ArrayLike | None = None, empty_sentinel: Any = '.', subplot_kw: Dict[str, Any] | None = None, per_subplot_kw: Dict[str, Any] | None = None, gridspec_kw: Dict[str, Any] | None = None)[source]#

Bases: NestedBuilder

Args and kwargs for Figure.subfigures routine.

Added in version 2.0.

__init__(mosaic, *, sharex: bool = False, sharey: bool = False, width_ratios: ArrayLike | None = None, height_ratios: ArrayLike | None = None, empty_sentinel: Any = '.', subplot_kw: Dict[str, Any] | None = None, per_subplot_kw: Dict[str, Any] | None = None, gridspec_kw: Dict[str, Any] | None = None) None[source]#

Build a layout of Axes based on ASCII art or nested lists.

This is a helper function to build complex GridSpec layouts visually.

See Complex and semantic figure composition (subplot_mosaic) for an example and full API documentation

Parameters:
  • mosaic (list of list of {hashable or nested} or str) –

    A visual layout of how you want your Axes to be arranged labeled as strings. For example

    x = [["A panel", "A panel", "edge"], ["C panel", ".", "edge"]]
    

    produces 4 Axes:

    • ’A panel’ which is 1 row high and spans the first two columns

    • ’edge’ which is 2 rows high and is on the right edge

    • ’C panel’ which in 1 row and 1 column wide in the bottom left

    • a blank space 1 row and 1 column wide in the bottom center

    Any of the entries in the layout can be a list of lists of the same form to create nested layouts.

    If input is a str, then it can either be a multi-line string of the form

    '''
    AAE
    C.E
    '''
    

    where each character is a column and each line is a row. Or it can be a single-line string where rows are separated by ;:

    "AB;CC"
    

    The string notation allows only single character Axes labels and does not support nesting but is very terse.

    The Axes identifiers may be str or a non-iterable hashable object (e.g. tuple s may not be used).

  • sharex (bool, default: False) – If True, the x-axis (sharex) or y-axis (sharey) will be shared among all subplots. In that case, tick label visibility and axis units behave as for subplots. If False, each subplot’s x- or y-axis will be independent.

  • sharey (bool, default: False) – If True, the x-axis (sharex) or y-axis (sharey) will be shared among all subplots. In that case, tick label visibility and axis units behave as for subplots. If False, each subplot’s x- or y-axis will be independent.

  • 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. Equivalent to gridspec_kw={'width_ratios': [...]}. In the case of nested layouts, this argument applies only to the outer layout.

  • 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. Equivalent to gridspec_kw={'height_ratios': [...]}. In the case of nested layouts, this argument applies only to the outer layout.

  • subplot_kw (dict, optional) – Dictionary with keywords passed to the .Figure.add_subplot call used to create each subplot. These values may be overridden by values in per_subplot_kw.

  • per_subplot_kw (dict, optional) –

    A dictionary mapping the Axes identifiers or tuples of identifiers to a dictionary of keyword arguments to be passed to the .Figure.add_subplot call used to create each subplot. The values in these dictionaries have precedence over the values in subplot_kw.

    If mosaic is a string, and thus all keys are single characters, it is possible to use a single string instead of a tuple as keys; i.e. "AB" is equivalent to ("A", "B").

  • gridspec_kw (dict, optional) – Dictionary with keywords passed to the .GridSpec constructor used to create the grid the subplots are placed on. In the case of nested layouts, this argument applies only to the outer layout. For more complex layouts, users should use .Figure.subfigures to create the nesting.

  • empty_sentinel (object, optional) – Entry in the layout to mean “leave this space empty”. Defaults to '.'. Note, if layout is a string, it is processed via inspect.cleandoc to remove leading white space, which may interfere with using white-space as the empty sentinel.

Public methods summary

__call__(fig, figname, grouped_sf_dict, ...)

Call self as a function.

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getstate__()

Helper for pickle.

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init__(mosaic, *[, sharex, sharey, ...])

Build a layout of Axes based on ASCII art or nested lists.

__init_subclass__()

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(*args, **kwargs)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__(object, /)

Abstract classes can override this to customize issubclass().

Methods definition

__call__(fig: Figure | SubFigure, figname: str, grouped_sf_dict: Dict[str, Dict[str, SubFigure]], grouped_ax_dict: Dict[str, Dict[str, Axes]]) None[source]#

Call self as a function.