Documentation

Combine Stem Plot and Line Plot

This example shows how to create a graph with a stem plot and two line plots.

Create a stem plot.

x = linspace(0,2*pi,60);
a = sin(x);
b = cos(x);
stem(x,a+b)

Overlay the stem plot with two line plots. Prevent new plots from replacing existing plots by using hold on.

hold on
plot(x,a)
plot(x,b)
hold off

Add a legend to the graph using the legend function. Specify the legend descriptions in the order you create the plots. Label the axis and add a title to the graph.

legend('a+b','a = sin(x)','b = cos(x)')
xlabel('Time in \musecs')
ylabel('Magnitude')
title('Linear Combination of Two Functions')

Was this topic helpful?