hold

Keeps existing plots when new ones are added to the same axes.

Category: Graphics > Formatting and Annotation

Syntax

hold on

Retains the current plots, so the next plotting commands add to them.

hold off

Restores the default, where a new plot replaces the old content.

hold

Toggles the hold state.

hold(ax, 'on')

Sets the state for the axes ax instead of the current axes.

Description

By default each call to a plotting function clears the axes first. With hold on, the new graphics are added instead, and the axis limits and the color order carry on from the previous lines, so successive plot calls get successive colors.

The function ishold tells whether hold is on for the current axes. Leave the state back at hold off once the extra lines are drawn, so that later plots in the script start clean.

Input arguments

ax
Axes to change. Optional.

Example

Two lines on one axes

x = 0:0.1:2*pi;
plot(x, sin(x))
hold on
plot(x, cos(x))
ishold
hold off
ishold
Output
ans = logical
   1
ans = logical
   0

See also

ishold plot figure clf cla