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);

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

hold on
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')
title('Linear Combination of Two Functions')

Was this topic helpful?