newplot

Prepares the figure and axes for a new plot, respecting hold and NextPlot settings.

Category: Graphics > Graphics Objects

Syntax

ax = newplot

Returns the axes a new plot should draw in, clearing them first unless hold is on.

ax = newplot(hsave)

Does the same for the figure or axes hsave.

Description

newplot is meant to be the first call inside a custom plotting function, so that the function follows the same rules as built-in ones: it creates a figure and axes if none exist, keeps the old content when hold on is active, and otherwise clears the axes.

Input arguments

hsave
Optional figure or axes to prepare.

Output arguments

ax
Handle of the axes to draw into.

Example

Clear unless hold is on

plot(1:3)
hold on
ax = newplot;
disp(numel(allchild(ax)))
hold off
ax = newplot;
disp(numel(allchild(ax)))
Output
     1
     0

See also

hold ishold cla gca axes