Plot a stem graph from two vectors of x-y data. If only one argument is given, it is taken as the y-values and the x coordinates are taken from the indicies of the elements.
If y is a matrix, then each column of the matrix is plotted as a separate stem graph. In this case x can either be a vector, the same length as the number of rows in y, or it can be a matrix of the same size as y.
The default color is
"r"
(red). The default line style is"-"
and the default marker is"o"
. The line style can be altered by thelinespec
argument in the same manner as theplot
command. For examplex = 1:10; y = ones (1, length (x))*2.*x; stem (x, y, "b");plots 10 stems with heights from 2 to 20 in blue;
The return value of
stem
is a vector if "stem series" graphics handles, with one handle per column of the variable y. This handle regroups the elements of the stem graph together as the children of the "stem series" handle, allowing them to be altered together. For examplex = [0 : 10].'; y = [sin(x), cos(x)] h = stem (x, y); set (h(2), "color", "g"); set (h(1), "basevalue", -1)changes the color of the second "stem series" and moves the base line of the first.
The following code
x = 1:10; stem (x);
Produces the following figure
![]() |
The following code
x = 1:10; y = ones (1, length (x))*2.*x; stem (x, y);
Produces the following figure
![]() |
The following code
x = 1:10; y = ones (size (x))*2.*x; h = stem (x, y, "b");
Produces the following figure
![]() |
The following code
x = 1:10; y = ones (size (x))*2.*x; h = stem (x, y, "-.k");
Produces the following figure
![]() |
The following code
x = 1:10; y = ones (size (x))*2.*x; h = stem (x, y, "-.k.");
Produces the following figure
![]() |
The following code
x = 1:10; y = ones (size (x))*2.*x; h = stem (x, y, "fill");
Produces the following figure
![]() |
The following code
x = [0 : 10].'; y = [sin(x), cos(x)]; h = stem (x, y); set (h(2), "color", "g"); set (h(1), "basevalue", -1)
Produces the following figure
![]() |