MATLAB® allows many figure windows to be open simultaneously during a session. You can control which figures and which axes MATLAB uses to display the result of plotting functions. You can also control to what extent MATLAB clears and resets the properties of the targeted figures and axes.
You can modify the way MATLAB plotting functions behave and you can implement specific behaviors in plotting functions that you write.
Consider these aspects:
Can you prevent a specific figure or axes from becoming the target for displaying graphs?
What happens to an existing graph when you plot more data to that graph? Is the existing graph replaced or are new graphics objects added to the existing graph?
By default, MATLAB plotting functions display graphs in
the current figure and current axes (the objects returned by
You can direct the output to another figure and axes by:
Explicitly specifying the target axes with the plotting function.
Making the target axes the current axes.
Suppose you create a figure with two axes,
tiledlayout(1,2) ax1 = nexttile; ax2 = nexttile;
plot with the axes object as the first
For plotting functions that do not support the axes first argument,
t = 0:pi/5:2*pi; patch(sin(t),cos(t),'y','Parent',ax2)
To specify a target, you can make a figure the current figure and an axes in that figure the current axes. Plotting functions use the current figure and its current axes by default. If the current figure has no current axes, MATLAB creates one.
fig is the handle to a figure, then the
fig the current figure.
fig to be the front-most figure
fig visible if it was not (sets the
Visible property to
Updates the figure display and processes any pending callbacks.
The same behavior applies to axes. If
the handle to an axes, then the statement
ax the current axes.
ax to be the front-most axes displayed.
ax visible if it was not.
Updates the figure containing the axes and process any pending callbacks.
You can make a figure or axes current without causing a change
in other aspects of the object state. Set the root
or the figure object's
CurrentAxes property to the handle of
the figure or axes that you want to target.
fig is the handle to an existing figure,
r = groot; r.CurrentFigure = fig;
fig the current figure. Similarly,
ax is the handle of an axes object, the statement
fig.CurrentAxes = ax;
makes it the current axes, if
fig is the
handle of the axes’ parent figure.