15.2.7 Manipulation of Plot Windows

By default, Octave refreshes the plot window when a prompt is printed, or when waiting for input. The drawnow function is used to cause a plot window to be updated.

: drawnow ()
: drawnow ("expose")
: drawnow (term, file, debug_file)

Update figure windows and their children.

The event queue is flushed and any callbacks generated are executed.

With the optional argument "expose", only graphic objects are updated and no other events or callbacks are processed.

The third calling form of drawnow is for debugging and is undocumented.

See also: refresh.

Only figures that are modified will be updated. The refresh function can also be used to cause an update of the current figure, even if it is not modified.

: refresh ()
: refresh (h)

Refresh a figure, forcing it to be redrawn.

When called without an argument the current figure is redrawn. Otherwise, the figure with graphic handle h is redrawn.

See also: drawnow.

Normally, high-level plot functions like plot or mesh call newplot to determine whether the state of the target axes should be initialized (the default) or if subsequent plots should be drawn on top of previous ones. To have two plots drawn over one another, use the hold function or manually change the axes nextplot property. For example,

hold on;
x = -10:0.1:10;
plot (x, sin (x));
plot (x, cos (x));
hold off;

displays sine and cosine waves on the same axes. If the hold state is off, consecutive plotting commands like this will only display the last plot.

: newplot ()
: newplot (hfig)
: newplot (hax)
: hax = newplot (…)

Prepare graphics engine to produce a new plot.

This function is called at the beginning of all high-level plotting functions. It is not normally required in user programs. newplot queries the "NextPlot" field of the current figure and axes to determine what to do.

Figure NextPlot Action
"new" Create a new figure and make it the current figure.
"add" (default) Add new graphic objects to the current figure.
"replacechildren" Delete child objects whose HandleVisibility is set to "on". Set NextPlot property to "add". This typically clears a figure, but leaves in place hidden objects such as menubars. This is equivalent to clf.
"replace" Delete all child objects of the figure and reset all figure properties to their defaults. However, the following four properties are not reset: Position, Units, PaperPosition, PaperUnits. This is equivalent to clf reset.
Axes NextPlot Action
"add" Add new graphic objects to the current axes. This is equivalent to hold on.
"replacechildren" Delete child objects whose HandleVisibility is set to "on", but leave axes properties unmodified. This typically clears a plot, but preserves special settings such as log scaling for axes. This is equivalent to cla.
"replace" (default) Delete all child objects of the axes and reset all axes properties to their defaults. However, the following properties are not reset: Position, Units. This is equivalent to cla reset.

If the optional input hfig or hax is given then prepare the specified figure or axes rather than the current figure and axes.

The optional return value hax is a graphics handle to the created axes object (not figure).

Caution: Calling newplot may change the current figure and current axes.

: hold
: hold on
: hold off
: hold (hax, …)

Toggle or set the "hold" state of the plotting engine which determines whether new graphic objects are added to the plot or replace the existing objects.

hold on

Retain plot data and settings so that subsequent plot commands are displayed on a single graph. Line color and line style are advanced for each new plot added.

hold all (deprecated)

Equivalent to hold on.

hold off

Restore default graphics settings which clear the graph and reset axes properties before each new plot command. (default).

hold

Toggle the current hold state.

When given the additional argument hax, the hold state is modified for this axes rather than the current axes returned by gca.

To query the current hold state use the ishold function.

See also: ishold, cla, clf, newplot.

: ishold
: ishold (hax)
: ishold (hfig)

Return true if the next plot will be added to the current plot, or false if the plot device will be cleared before drawing the next plot.

If the first argument is an axes handle hax or figure handle hfig then operate on this plot rather than the current one.

See also: hold, newplot.

To clear the current figure, call the clf function. To clear the current axis, call the cla function. To bring the current figure to the top of the window stack, call the shg function. To delete a graphics object, call delete on its index. To close the figure window, call the close function.

: clf
: clf reset
: clf (hfig)
: clf (hfig, "reset")
: h = clf (…)

Clear the current figure window.

clf operates by deleting child graphics objects with visible handles (HandleVisibility = "on").

If the optional argument "reset" is specified, delete all child objects including those with hidden handles and reset all figure properties to their defaults. However, the following properties are not reset: Position, Units, PaperPosition, PaperUnits.

If the first argument hfig is a figure handle, then operate on this figure rather than the current figure returned by gcf.

The optional return value h is the graphics handle of the figure window that was cleared.

See also: cla, close, delete, reset.

: cla
: cla reset
: cla (hax)
: cla (hax, "reset")

Clear the current or specified (hax) axes object.

cla operates by deleting child graphic objects with visible handles (HandleVisibility = "on"). This typically clears the axes of any visual objects, but leaves in place axes limits, tick marks and labels, camera view, etc. In addition, the automatic coloring and styling of lines is reset by changing the axes properties ColorOrderIndex, LinestyleOrderIndex to 1.

If the optional argument "reset" is specified, delete all child objects, including those with hidden handles, and reset all axes properties to their defaults. However, the following properties are not reset: Position, Units.

If the first argument hax is an axes handle, then operate on this axes rather than the current axes returned by gca.

See also: clf, delete, reset.

: shg

Show the graph window.

This function makes the current figure visible, and places it on top of of all other plot windows.

Programming Note: shg is equivalent to figure (gcf) assuming that a current figure exists.

See also: figure, drawnow, gcf.

: delete (file)
: delete (file1, file2, …)
: delete (handle)

Delete the named file or graphics handle.

file may contain globbing patterns such as ‘*’. Multiple files to be deleted may be specified in the same function call.

handle may be a scalar or vector of graphic handles to delete.

Programming Note: Deleting graphics objects is the proper way to remove features from a plot without clearing the entire figure.

See also: clf, cla, unlink, rmdir.

: close
: close (h)
: close figname
: close all
: close all hidden
: close all force

Close figure window(s).

When called with no arguments, close the current figure. This is equivalent to close (gcf). If the input h is a graphic handle, or vector of graphics handles, then close each figure in h. The figure to close may also be specified by name figname which is matched against the "Name" property of all figures.

If the argument "all" is given then all figures with visible handles (HandleVisibility = "on") are closed.

If the additional argument "hidden" is given then all figures, including hidden ones, are closed.

If the additional argument "force" is given then figures are closed even when "closerequestfcn" has been altered to prevent closing the window.

Implementation Note: close operates by making the handle h the current figure, and then calling the function specified by the "closerequestfcn" property of the figure. By default, the function closereq is used. It is possible that the function invoked will delay or abort removing the figure. To remove a figure without executing any callback functions use delete. When writing a callback function to close a window do not use close to avoid recursion.

See also: closereq, delete.

: closereq ()

Close the current figure and delete all graphics objects associated with it.

By default, the "closerequestfcn" property of a new plot figure points to this function.

See also: close, delete.

© 1996–2020 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/v6.3.0/Manipulation-of-Plot-Windows.html