Create axes in tiled positions
subplot(
divides
the current figure into an m
,n
,p
)m
-by-n
grid
and creates axes in the position specified by p
. MATLAB® numbers
subplot positions by row. The first subplot is the first column of
the first row, the second subplot is the second column of the first
row, and so on. If axes exist in the specified position, then this
command makes the axes the current axes.
subplot(
creates
axes in the custom position specified by 'Position'
,pos
)pos
. Use
this option to position a subplot that does not align with grid positions.
Specify pos
as a four-element vector of the form [left
bottom width height]
. If the new axes overlap existing axes,
then the new axes replace the existing axes.
subplot(___,
modifies axes
properties using one or more name-value pair arguments. Set axes properties
after all other input arguments.Name,Value
)
To clear the contents of the figure, use clf
.
For example, you might clear the existing subplot layout from the
figure before creating a new subplot layout.
To overlay axes, use the axes
command
instead. The subplot
function deletes existing
axes that overlap new axes. For example, subplot('Position',[.35
.35 .3 .3])
deletes any underlying axes, but axes('Position',[.35
.35 .3 .3])
positions new axes in the middle of the figure
without deleting underlying axes.
subplot(111)
is an exception and
not identical in behavior to subplot(1,1,1)
. For
reasons of backwards compatibility, subplot(111)
is
a special case of subplot that does not immediately create axes, but
sets up the figure so that the next graphics command executes clf
reset
. The next graphics command deletes all the figure
children and creates new axes in the default position. subplot(111)
does
not return an Axes
object and an error occurs if
code specifies a return argument.
Use the tiledlayout
and nexttile
functions to create a configurable tiling of plots. The configuration options include:
Control over the spacing between the plots and around the edges of the layout
An option for a shared title at the top of the layout
Options for shared x- and y-axis labels
An option to control whether the tiling has a fixed size or variable size that can reflow
For more information, see Combine Multiple Plots.