Retain current plot when adding new plots
hold on retains plots in the current axes
so that new plots added to the axes do not delete existing plots.
New plots use the next colors and line styles based on the
of the axes. MATLAB® adjusts axes limits, tick marks, and tick
labels to display the full range of data. If axes do not exist, then
hold command creates them.
hold off sets the hold state to off so
that new plots added to the axes clear existing plots and reset all
axes properties. The next plot added to the axes uses the first color
and line style based on the
of the axes. This option is the default behavior.
hold all is the same as
This syntax will be removed in a future release. Use
hold toggles the hold state between on
Create a line plot. Use
hold on to add a second line plot without deleting the existing line plot. The new plot uses the next color and line style based on the
LineStyleOrder properties of the axes. Then reset the hold state to off.
x = linspace(-pi,pi); y1 = sin(x); plot(x,y1) hold on y2 = cos(x); plot(x,y2) hold off
When the hold state is off, new plots delete existing plots. New plots start from the beginning of the color order and line style order.
y3 = sin(2*x); plot(x,y3)
Create a figure with two subplots and assign the
Axes objects to the variables
ax2. Add a line plot to each subplot. Then add a second line plot to the upper subplot.
ax1 = subplot(2,1,1); x = linspace(0,10); y1 = sin(x); plot(ax1,x,y1) ax2 = subplot(2,1,2); y2 = cos(x); plot(ax2,x,y2)
hold(ax1,'on') y3 = sin(2*x); plot(ax1,x,y3) hold(ax1,'off')
ax— Target axes
Target axes, specified as an
Axes object or
PolarAxes object. If you do not specify the axes,
hold sets the hold state for the current axes.
ishold function to test
the hold state.
hold function sets the
NextPlot property of the
PolarAxes object to either