matplotlib 3.5.1

ParametersReturnsBackRef
subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw)

This utility wrapper makes it convenient to create common layouts of subplots, including the enclosing figure object, in a single call.

Parameters

nrows, ncols : int, default: 1

Number of rows/columns of the subplot grid.

sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False

Controls sharing of properties among x (sharex) or y (sharey) axes:

  • True or 'all': x- or y-axis will be shared among all subplots.

  • False or 'none': each subplot x- or y-axis will be independent.

  • 'row': each subplot row will share an x- or y-axis.

  • 'col': each subplot column will share an x- or y-axis.

When subplots have a shared x-axis along a column, only the x tick labels of the bottom subplot are created. Similarly, when subplots have a shared y-axis along a row, only the y tick labels of the first column subplot are created. To later turn other subplots' ticklabels on, use tick_params .

When subplots have a shared axis that has units, calling ~matplotlib.axis.Axis.set_units will update each axis with the new units.

squeeze : bool, default: True
  • If True, extra dimensions are squeezed out from the returned array of Axes :

    • if only one subplot is constructed (nrows=ncols=1), the resulting single Axes object is returned as a scalar.

    • for Nx1 or 1xM subplots, the returned object is a 1D numpy object array of Axes objects.

    • for NxM, subplots with N>1 and M>1 are returned as a 2D array.

  • If False, no squeezing at all is done: the returned Axes object is always a 2D array containing Axes instances, even if it ends up being 1x1.

subplot_kw : dict, optional

Dict with keywords passed to the add_subplot call used to create each subplot.

gridspec_kw : dict, optional

Dict with keywords passed to the ~matplotlib.gridspec.GridSpec constructor used to create the grid the subplots are placed on.

**fig_kw :

All additional keyword arguments are passed to the .pyplot.figure call.

Returns

fig : `~.figure.Figure`
ax : `.axes.Axes` or array of Axes

ax can be either a single Axes object or an array of Axes objects if more than one subplot was created. The dimensions of the resulting array can be controlled with the squeeze keyword, see above.

Typical idioms for handling the return value are:

# using the variable ax for single a Axes
fig, ax = plt.subplots()

# using the variable axs for multiple Axes
fig, axs = plt.subplots(2, 2)

# using tuple unpacking for multiple Axes
fig, (ax1, ax2) = plt.subplots(1, 2)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

The names ax and pluralized axs are preferred over axes because for the latter it's not clear if it refers to a single :None:None:`~.axes.Axes` instance or a collection of these.

Create a figure and a set of subplots.

See Also

.Figure.add_subplot
.Figure.subplots
.pyplot.axes
.pyplot.figure
.pyplot.subplot

Examples

# First create some toy data: x = np.linspace(0, 2*np.pi, 400) y = np.sin(x**2)

# Create just a figure and only one subplot fig, ax = plt.subplots() ax.plot(x, y) ax.set_title('Simple plot')

# Create two subplots and unpack the output array immediately f, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title('Sharing Y axis') ax2.scatter(x, y)

# Create four polar axes and access them through the returned array fig, axs = plt.subplots(2, 2, subplot_kw=dict(projection="polar")) axs[0, 0].plot(x, y) axs[1, 1].scatter(x, y)

# Share a X axis with each column of subplots plt.subplots(2, 2, sharex='col')

# Share a Y axis with each row of subplots plt.subplots(2, 2, sharey='row')

# Share both X and Y axes with all subplots plt.subplots(2, 2, sharex='all', sharey='all')

# Note that this is the same as plt.subplots(2, 2, sharex=True, sharey=True)

# Create figure number 10 with a single subplot # and clears it if it already exists. fig, ax = plt.subplots(num=10, clear=True)

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

matplotlib

13 Elements
matplotlib.gridspec.SubplotSpec.subgridspec
matplotlib
matplotlib.pyplot
matplotlib.figure.FigureBase.add_gridspec
matplotlib.pyplot.subplot
matplotlib.widgets.RectangleSelector
matplotlib.pyplot.axes
matplotlib.figure.FigureBase.add_subplot
matplotlib.figure.FigureBase.subplots
matplotlib.pyplot.plotting
matplotlib.figure.FigureBase.add_axes
matplotlib.widgets.SpanSelector
matplotlib.gridspec

scipy

39 Elements
scipy.signal._signaltools.correlate2d
scipy.signal._signaltools.wiener
scipy.special._orthogonal.chebyu
scipy.optimize._zeros_py.newton
scipy.interpolate._bsplines.BSpline
scipy.signal._fir_filter_design.minimum_phase
scipy.signal._filter_design.ellip
scipy.special._spherical_bessel.spherical_kn
scipy.special._orthogonal.gegenbauer
scipy.special._orthogonal.jacobi
scipy.special._spherical_bessel.spherical_yn
scipy.special._orthogonal.genlaguerre
scipy.signal._signaltools.fftconvolve
scipy.signal._filter_design.iirnotch
scipy.signal.windows._windows.general_hamming
scipy.signal._spectral_py.lombscargle
scipy.signal._filter_design.freqz
scipy.signal._filter_design.iirpeak
scipy.signal._bsplines.spline_filter
scipy.special._orthogonal.chebyt
scipy.signal._filter_design.butter
scipy.interpolate._bsplines.BSpline.integrate
scipy.signal._fir_filter_design.firls
scipy.signal._signaltools.convolve
scipy.special._spherical_bessel.spherical_jn
scipy.special._orthogonal.laguerre
scipy.signal._filter_design.iircomb
scipy.special._spherical_bessel.spherical_in
scipy.signal._lti_conversion.cont2discrete
scipy.signal._filter_design.cheby1
scipy.signal._signaltools.hilbert
scipy.signal._filter_design.iirdesign
scipy.signal._signaltools.correlate
scipy.signal._filter_design.cheby2
scipy.interpolate._cubic.CubicSpline
scipy.signal._signaltools.convolve2d
scipy.interpolate._rbfinterp.RBFInterpolator
scipy.signal.windows._windows.dpss
scipy.signal._signaltools.oaconvolve

networkx

networkx.drawing.nx_pylab.draw_networkx_edges

papyri

papyri.examples.example1

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /matplotlib/pyplot.py#1300
type: <class 'function'>
Commit: