matplotlib.pyplot.subplot_mosaic#

matplotlib.pyplot.subplot_mosaic(mosaic,*,sharex=False,sharey=False,width_ratios=None,height_ratios=None,empty_sentinel='.',subplot_kw=None,gridspec_kw=None,per_subplot_kw=None,**fig_kw)[source]#

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

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

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

Parameters:
mosaiclist of list of {hashable or nested} or str

A visual layout of how you want your Axes to be arrangedlabeled 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 listsof the same form to create nested layouts.

If input is a str, then it must be of the form

'''AAEC.E'''

where each character is a column and each line is a row.This only allows only single character Axes labels and doesnot allow nesting but is very terse.

sharex, shareybool, default: False

If True, the x-axis (sharex) or y-axis (sharey) will be sharedamong all subplots. In that case, tick label visibility and axis unitsbehave as forsubplots. If False, each subplot's x- or y-axis willbe independent.

width_ratiosarray-like of lengthncols, optional

Defines the relative widths of the columns. Each column gets arelative width ofwidth_ratios[i]/sum(width_ratios).If not given, all columns will have the same width. Convenienceforgridspec_kw={'width_ratios':[...]}.

height_ratiosarray-like of lengthnrows, optional

Defines the relative heights of the rows. Each row gets arelative height ofheight_ratios[i]/sum(height_ratios).If not given, all rows will have the same height. Convenienceforgridspec_kw={'height_ratios':[...]}.

empty_sentinelobject, optional

Entry in the layout to mean "leave this space empty". Defaultsto'.'. Note, iflayout is a string, it is processed viainspect.cleandoc to remove leading white space, which mayinterfere with using white-space as the empty sentinel.

subplot_kwdict, optional

Dictionary with keywords passed to theFigure.add_subplot callused to create each subplot. These values may be overridden byvalues inper_subplot_kw.

per_subplot_kwdict, optional

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

Ifmosaic 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").

Added in version 3.7.

gridspec_kwdict, optional

Dictionary with keywords passed to theGridSpec constructor usedto create the grid the subplots are placed on.

**fig_kw

All additional keyword arguments are passed to thepyplot.figure call.

Returns:
figFigure

The new figure

dict[label, Axes]

A dictionary mapping the labels to the Axes objects. The order ofthe Axes is left-to-right and top-to-bottom of their position in thetotal layout.

Examples usingmatplotlib.pyplot.subplot_mosaic#

Many ways to plot images

Many ways to plot images

Power spectral density (PSD)

Power spectral density (PSD)

Scatter plot with histograms

Scatter plot with histograms

Primary 3D view planes

Primary 3D view planes

MRI with EEG

MRI with EEG

Spine placement

Spine placement

Histogram bins, density, and weight

Histogram bins, density, and weight

Figure size in different units

Figure size in different units

Labelling subplots

Labelling subplots

mplcvd -- an example of figure hook

mplcvd -- an example of figure hook

Radio Buttons

Radio Buttons

Arranging multiple Axes in a Figure

Arranging multiple Axes in a Figure

Axis scales

Axis scales

Legend guide

Legend guide

Complex and semantic figure composition (subplot_mosaic)

Complex and semantic figure composition (subplot_mosaic)

Quick start guide

Quick start guide