Skip to content

Axes facets

daspi.plotlib.facets.AxesFacets(*, nrows=None, ncols=None, mosaic=None, sharex='none', sharey='none', width_ratios=None, height_ratios=None, stretch_figsize=False, **kwds)

A class for creating a grid of subplots with customizable sharing and sizing options.

The class provides flexible handling the created Axes instances through its flat property and iteration capabilities:

  • Flat property: Accesses Axes in a flattened view from left-to-right, top-to-bottom
  • Axes property: Maintains the 2D structure for grid-based operations
  • Iteration: Yields each axis instance coming from the Flat property sequentially to simplify plotting The class supports two different ways to create subplot layouts:
PARAMETER DESCRIPTION
nrows

Number of rows of subplots in the grid, by default 1.

TYPE: int DEFAULT: None

ncols

Number of columns of subplots in the grid, by default 1.

TYPE: int DEFAULT: None

sharex

Controls sharing of properties along the x-axis, by default 'none'.

TYPE: bool or {none, all, row, col} DEFAULT: 'none'

sharey

Controls sharing of properties along the y-axis, by default 'none'.

TYPE: bool or {none, all, row, col} DEFAULT: 'none'

width_ratios

Relative widths of the columns, by default None.

TYPE: array-like of length ncols DEFAULT: None

height_ratios

Relative heights of the rows, by default None.

TYPE: array-like of length nrows DEFAULT: None

stretch_figsize

If True, the height and width of the figure are stretched based on the number rows and columns in the axes grid. If a float is provided, the figure size is stretched by the given factor. If a tuple of two floats is provided, the figure size is stretched by the given factors for the x and y axis, respectively. by default False.

TYPE: bool | float | Tuple[float, float] DEFAULT: False

**kwds

Additional keyword arguments to pass to the function plt.subplots or to the function plt.subplot_mosaic if a mosaic was specified.

TYPE: dict DEFAULT: {}

Examples:

  1. Using nrows and ncols: Creates a regular grid of subplots with specified dimensions

    # Creates a 2x3 grid of regular subplots
    facets = AxesFacets(nrows=2, ncols=3)
    

  2. Using mosaic: Creates a layout with custom subplot arrangements and spanning

    import daspi as dsp
    # Creates a layout with spanning cells
    layout = (
        'AAB',
        'CDB')
    facets = dsp.AxesFacets(mosaic=layout)
    

  3. Create a seaborn-style jointplot layout with custom size ratios:

    import daspi as dsp
    # Creates a layout with main scatter plot and marginal distributions
    layout = [
        ['hist_x', '.'],      # '.' creates an empty/blank Axes
        ['scatter', 'hist_y']]
    facets = AxesFacets(
        mosaic=layout,
        width_ratios=[4, 1],   # Make the marginal y-hist narrower
        height_ratios=[1, 4]   # Make the marginal x-hist shorter
        )
    

This creates a figure with: - A main scatter plot in the bottom-left - A marginal histogram on top for x-distribution - A marginal histogram on right for y-distribution - Top-right cell is automatically empty using the '.' notation - Proportional spacing using width and height ratios

The '.' character is a special notation in matplotlib's mosaic layout that automatically creates an empty/invisible Axes, which is more efficient than creating a visible Axes and then hiding it.

figure instance-attribute

The figure instance to label.

axes instance-attribute

A 2D array containing the Axes instances of the figure.

mosaic instance-attribute

A visual layout of how the Axes are arranged labeled as strings.

figsize = (stretch_x * figsize[0], stretch_y * figsize[1]) instance-attribute

The figsize passed when creating the subplots.

ax property

Get the axes that is currently being worked on. This property is automatically kept current when iterating through this class (read-only).

nrows property

Get the number of Axes rows in the grid (read-only).

ncols property

Get the number of Axes columns in the grid (read-only).

shape property

Get the shape of the axes array (read-only).

sharex property

Get the sharing of properties along the x-axis (read-only).

sharey property

Get the sharing of properties along the y-axis (read-only).

flat property

Get a list of all the Axes in the grid.

RETURNS DESCRIPTION
List[Axes]

A list of all the Axes in the grid.