This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Control Graph Display

What You Can Control

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?

Targeting Specific Figures and Axes

By default, MATLAB plotting functions display graphs in the current figure and current axes (the objects returned by gcf and gca respectively). 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.

Specify the Target Axes

Suppose you create a figure with four axes and save the handles in the array ax:

for k = 1:4
   ax(k) = subplot(2,2,k);

Call plot with the axes handle as the first argument:


For plotting functions that do not support the axes first argument, set the Parent property:

t = 0:pi/5:2*pi;

Make the Target Current

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.

If fig is the handle to a figure, then the statement

  • Makes fig the current figure.

  • Restacks fig to be the frontmost figure displayed.

  • Makes fig visible if it was not (sets the Visible property to on).

  • Updates the figure display and processes any pending callbacks.

The same behavior applies to axes. If ax is the handle to an axes, then the statement

  • Makes ax the current axes.

  • Restacks ax to be the frontmost axes displayed.

  • Makes ax visible if it was not.

  • Updates the figure containing the axes and process any pending callbacks.

Make Figure or Axes Current Without Changing Other State

You can make a figure or axes current without causing a change in other aspects of the object state. Set the root CurrentFigure property or the figure object's CurrentAxes property to the handle of the figure or axes that you want to target.

If fig is the handle to an existing figure, the statement

r = groot;
r.CurrentFigure = fig;

makes fig the current figure. Similarly, if 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.