This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Add Plot to Existing Graph

This example shows how to add a plot to an existing graph.

Plot of a sine wave along the domain [0,5].

x1 = linspace(0,5);
y1 = sin(x1);

figure % new figure window

Use hold on to retain the line plot and add a new plot to the graph. Add a stem plot along the domain [0,8]. Then, use hold off to reset the hold state so that new plots replace existing plots, which is the default behavior.

hold on

x2 = 0:0.5:8;
y2 = 0.5*sin(x2);

hold off % reset hold state

MATLAB® rescales the axis limits each time a new plot is added to a graph.

See Also

| | |

Related Examples

Was this topic helpful?