Figure.subplots¶
- Figure.subplots(*args, **kwargs)[source]¶
Add an arbitrary grid of subplots to the figure.
- Parameters
array (array-like of
int, optional) – A 2D array specifying complex grid of subplots. Think of this as a “picture” of your figure. For example, the array[[1, 1], [2, 3]]creates one long subplot in the top row, two smaller subplots in the bottom row. Integers must range from 1 to the number of plots, and0indicates an empty space. For example,[[1, 1, 1], [2, 0, 3]]creates one long subplot in the top row with two subplots in the bottom row separated by a space.ncols, nrows (
int, optional) – The number of columns, rows in the subplot grid. Ignored ifarraywas passed. Use these arguments for simpler subplot grids.order (
{'C', 'F'}, optional) – Whether subplots are numbered in column-major ('C') or row-major ('F') order. Analogous tonumpy.arrayordering. This controls the order that subplots appear in theSubplotGridreturned by this function, and the order of subplot a-b-c labels (seeformat).proj, projection (
str,cartopy.crs.Projection, orBasemap, optional) – The map projection specification(s). If'cart'or'cartesian'(the default), aCartesianAxesis created. If'polar', aPolarAxesis created. Otherwise, the argument is interpreted byProj, and the result is used to make aGeoAxes(in this case the argument can be acartopy.crs.Projectioninstance, aBasemapinstance, or a projection name listed in this table).To use different projections for different subplots, you have two options:
Pass a list of projection specifications, one for each subplot. For example,
pplt.subplots(ncols=2, proj=('cart', 'robin')).Pass a dictionary of projection specifications, where the keys are integers or tuples of integers that indicate the projection to use for the corresponding subplot number(s). If a key is not provided, the default projection
'cartesian'is used. For example,pplt.subplots(ncols=4, proj={2: 'cyl', (3, 4): 'stere'})creates a figure with a default Cartesian axes for the first subplot, a Mercator projection for the second subplot, and a Stereographic projection for the third and fourth subplots.
proj_kw, projection_kw (dict-like, optional) – Keyword arguments passed to
Basemapor cartopyProjectionclasses on instantiation. If dictionary of properties, applies globally. If list or dictionary of dictionaries, applies to specific subplots, as withproj. For example,pplt.subplots(ncols=2, proj='cyl', proj_kw=({'lon_0': 0}, {'lon_0': 180})centers the projection in the left subplot on the prime meridian and in the right subplot on the international dateline.basemap (
boolor dict-like, optional) – Whether to useBasemaporProjectionfor map projections. Default isrc.basemap=False. If boolean, applies to all subplots. If list or dict, applies to specific subplots, as withproj.left, right, top, bottom (
unit-spec, optional) – The fixed space between the subplots and the figure edge. Default isNone. If float, units are em-widths. If string, interpreted byunits. IfNone, the space is determined automatically based on the tick and label settings. Ifrc['subplots.tight']isTrueortight=Truewas passed to the figure, the space is determined by the tight layout algorithm.wspace, hspace, space (
unit-specor sequence, optional) – The fixed space between grid columns, rows, and both, respectively. If float, string, orNone, this value is expanded into lists of lengthncols - 1(forwspace) or lengthnrows - 1(forhspace). If a sequence, its length must match these lengths. Default isNone. If float, units are em-widths. If string, interpreted byunits.For elements equal to
None, the space is determined automatically based on the tick and label settings. Ifrc['subplots.tight']isTrueortight=Truewas passed to the figure, the space is determined by the tight layout algorithm. For example,subplots(ncols=3, tight=True, wspace=(2, None))fixes the space between columns 1 and 2 but lets the tight layout algorithm determine the space between columns 2 and 3.wratios, hratios (
floator sequence, optional) – Passed toGridSpec, denotes the width and height ratios for the subplot grid. Length ofwratiosmust match the number of rows, and length ofhratiosmust match the number of columns.width_ratios, height_ratios – Aliases for
wratios,hratios. Included for consistency withmatplotlib.gridspec.GridSpec.wpad, hpad, pad (
unit-specor sequence, optional) – The tight layout padding between columns, rows, and both, respectively. Unlikespace, these control the padding between subplot content (including text, ticks, etc.) rather than subplot edges. As withspace, these can be scalars or arrays optionally containingNone. For elements equal toNone, the default isinnerpad. If float, units are em-widths. If string, interpreted byunits.wequal, hequal, equal (
bool, optional) – Whether to make the tight layout algorithm apply equal spacing between columns, rows, or both. Default isFalse.outerpad (
unit-spec, optional) – The scalar tight layout padding around the left, right, top, and bottom edges of the figure. Default isrc['subplots.outerpad']=0.5. If float, units are em-widths. If string, interpreted byunits.innerpad (
unit-spec, optional) – The scalar tight layout padding between columns and rows. Synonymous withpad. Default isrc['subplots.innerpad']=1.0. If float, units are em-widths. If string, interpreted byunits.panelpad (
unit-spec, optional) – The scalar tight layout padding between subplots and their panels, colorbars, and legends and between “stacks” of these objects. Default isrc['subplots.panelpad']=0.5. If float, units are em-widths. If string, interpreted byunits.
- Other Parameters
refnum (
int, optional) – The reference subplot number. Therefwidth,refheight, andrefaspectkeyword args are applied to this subplot, and the aspect ratio is conserved for this subplot in theauto_layout. The default is the first subplot created in the figure.refaspect (
floator2-tupleoffloat, optional) – The reference subplot aspect ratio. If scalar, this indicates the width divided by height. If 2-tuple, indicates the (width, height). Ignored if bothfigwidthandfigheightor bothrefwidthandrefheightwere passed.refwidth, refheight (
unit-spec, optional) – The width, height of the reference subplot. Default isrc['subplots.refwidth']=2.5. If float, units are inches. If string, interpreted byunits. Ignored iffigwidth,figheight, orfigsizewas passed. If you specify just one,refaspectwill be respected.ref, aspect, axwidth, axheight – Aliases for
refnum,refaspect,refwidth,refheight. These may be deprecated in a future release.figwidth, figheight (
unit-spec, optional) – The figure width and height. Default behavior is to userefwidth. If float, units are inches. If string, interpreted byunits. If you specify just one,refaspectwill be respected.width, height – Aliases for
figwidth,figheight.figsize (
2-tuple, optional) – Tuple specifying the figure(width, height).sharex, sharey, share (
{0, False, 1, 'labels', 'labs', 2, 'limits', 'lims', 3, True, 4, 'all'}, optional) – The axis sharing “level” for the x axis, y axis, or both axes. Default isrc['subplots.share']=True. Options are as follows:0orFalse: No axis sharing. This also sets the defaultspanxandspanyvalues toFalse.1or'labels'or'labs': Only draw axis labels on the bottommost row or leftmost column of subplots. Tick labels still appear on every subplot.2or'limits'or'lims': As above but force the axis limits, scales, and tick locations to be identical. Tick labels still appear on every subplot.3orTrue: As above but only show the tick labels on the bottommost row and leftmost column of subplots.4or'all': As above but also share the axis limits, scales, and tick locations between subplots not in the same row or column.
spanx, spany, span (
boolor{0, 1}, optional) – Whether to use “spanning” axis labels for the x axis, y axis, or both axes. Default isFalseifsharex,sharey, orshareare0orFalse,rc['subplots.span']=Trueotherwise. WhenTrue, a single, centered axis label is used for all axes with bottom and left edges in the same row or column. This can considerably redundancy in your figure.“Spanning” labels integrate with “shared” axes. For example, for a 3-row, 3-column figure, with
sharey > 1andspany=1, your figure will have 1 ylabel instead of 9.alignx, aligny, align (
boolor{0, 1}, optional) – Whether to “align” axis labels for the x axis, y axis, or both axes. Aligned labels always appear in the same row or column. This Only has an effect whenspanx,spany, orspanareFalse. Default isrc['subplots.align']=False.left, right, top, bottom (
unit-spec, optional) – The fixed space between the subplots and the figure edge. Default isNone. If float, units are em-widths. If string, interpreted byunits. IfNone, the space is determined automatically based on the tick and label settings. Ifrc['subplots.tight']isTrueortight=Truewas passed to the figure, the space is determined by the tight layout algorithm.wspace, hspace, space (
unit-spec, optional) – The fixed space between grid columns, rows, or both. Default isNone. If float, units are em-widths. If string, interpreted byunits. IfNone, the space is determined automatically based on the font size and axis sharing settings. Ifrc['subplots.tight']isTrueortight=Truewas passed to the figure, the space is determined by the tight layout algorithm.tight (
bool, optional) – Whether to haveauto_layoutinclude tight layout adjustments. Default isrc['subplots.tight']=True. If you manually specified a spacing in the call tosubplots, it will be used to override the tight layout spacing. For example, withleft=1, the left margin is set to 1 em-width, while the remaining margin widths are calculated automatically.wequal, hequal, equal (
bool, optional) – Whether to make the tight layout algorithm apply equal spacing between columns, rows, or both. Default isFalse.outerpad (
unit-spec, optional) – The scalar tight layout padding around the left, right, top, and bottom edges of the figure. Default isrc['subplots.outerpad']=0.5. If float, units are em-widths. If string, interpreted byunits.innerpad (
unit-spec, optional) – The scalar tight layout padding between columns and rows. Synonymous withpad. Default isrc['subplots.innerpad']=1.0. If float, units are em-widths. If string, interpreted byunits.panelpad (
unit-spec, optional) – The scalar tight layout padding between subplots and their panels, colorbars, and legends and between “stacks” of these objects. Default isrc['subplots.panelpad']=0.5. If float, units are em-widths. If string, interpreted byunits.journal (
str, optional) – String corresponding to an academic journal standard used to control the figure widthfigwidthand, if specified, the figure heightfigheight. See the below table. Feel free to add to this table by submitting a pull request.Key
Size description
Organization
'aaas1'1-column
American Association for the Advancement of Science (e.g. Science)
'aaas2'2-column
”
'agu1'1-column
'agu2'2-column
”
'agu3'full height 1-column
”
'agu4'full height 2-column
”
'ams1'1-column
'ams2'small 2-column
”
'ams3'medium 2-column
”
'ams4'full 2-column
”
'nat1'1-column
'nat2'2-column
”
'pnas1'1-column
'pnas2'2-column
”
'pnas3'landscape page
”
**kwargs – Passed to the proplot class
proplot.axes.CartesianAxes,proplot.axes.PolarAxes,proplot.axes.GeoAxes, orproplot.axes.ThreeAxes. This can include keyword arguments for projection-specificformatcommands.
- Returns
axs (
SubplotGrid) – The axes instances stored in aSubplotGrid.