matplotlib.figure.SubFigure.add_subplot#
- SubFigure.add_subplot(*args,**kwargs)[source]#
Add an
Axesto the figure as part of a subplot arrangement.Call signatures:
add_subplot(nrows,ncols,index,**kwargs)add_subplot(pos,**kwargs)add_subplot(ax)add_subplot()
- Parameters:
- *argsint, (int, int,index), or
SubplotSpec, default: (1, 1, 1) The position of the subplot described by one of
Three integers (nrows,ncols,index). The subplot willtake theindex position on a grid withnrows rows andncols columns.index starts at 1 in the upper left cornerand increases to the right.index can also be a two-tuplespecifying the (first,last) indices (1-based, and includinglast) of the subplot, e.g.,
fig.add_subplot(3,1,(1,2))makes a subplot that spans the upper 2/3 of the figure.A 3-digit integer. The digits are interpreted as if givenseparately as three single-digit integers, i.e.
fig.add_subplot(235)is the same asfig.add_subplot(2,3,5). Note that this can only be usedif there are no more than 9 subplots.
In rare circumstances,
add_subplotmay be called with a singleargument, a subplot Axes instance already created in thepresent figure but not in the figure's list of Axes.- projection{None, 'aitoff', 'hammer', 'lambert', 'mollweide', 'polar', 'rectilinear', str}, optional
The projection type of the subplot (
Axes).str is thename of a custom projection, seeprojections. Thedefault None results in a 'rectilinear' projection.- polarbool, default: False
If True, equivalent to projection='polar'.
- axes_classsubclass type of
Axes, optional The
axes.Axessubclass that is instantiated. This parameteris incompatible withprojection andpolar. Seeaxisartist for examples.- sharex, sharey
Axes, optional Share the x or y
axiswith sharex and/or sharey.The axis will have the same limits, ticks, and scale as the axisof the shared Axes.- labelstr
A label for the returned Axes.
- *argsint, (int, int,index), or
- Returns:
AxesThe Axes of the subplot. The returned Axes can actually be aninstance of a subclass, such as
projections.polar.PolarAxesforpolar projections.
- Other Parameters:
- **kwargs
This method also takes the keyword arguments for the returned Axesbase class; except for thefigure argument. The keyword argumentsfor the rectilinear base class
Axescan be found inthe following table but there might also be other keywordarguments if another projection is used.Property
Description
{'box', 'datalim'}
a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image
float or None
(float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', ...}
bool
{'auto', 'equal'} or float
bool
unknown
unknown
Callable[[Axes, Renderer], Bbox]
bool or 'line'
float or None
BboxBaseor Nonebool
Patch or (Path, Transform) or None
bool or "auto"
bool
str
bool
object
bool
bool
unknown
list of
AbstractPathEffectNone or bool or float or callable
[left, bottom, width, height] or
Bboxfloat or None
bool
(scale: float, length: float, randomness: float)
bool or None
unknown
str
str
bool
(lower: float, upper: float)
unknown
str
(left: float, right: float)
float greater than -0.5
unknown
unknown
unknown
(lower: float, upper: float)
unknown
str
(bottom: float, top: float)
float greater than -0.5
unknown
unknown
unknown
float
Examples
fig=plt.figure()fig.add_subplot(231)ax1=fig.add_subplot(2,3,1)# equivalent but more generalfig.add_subplot(232,frameon=False)# subplot with no framefig.add_subplot(233,projection='polar')# polar subplotfig.add_subplot(234,sharex=ax1)# subplot sharing x-axis with ax1fig.add_subplot(235,facecolor="red")# red subplotax1.remove()# delete ax1 from the figurefig.add_subplot(ax1)# add ax1 back to the figure