stem(Y) plots the
data sequence, Y, as stems that extend from a baseline
along the x-axis. The data values are indicated
by circles terminating each stem.

If Y is a vector, then the x-axis
scale ranges from 1 to length(Y).

If Y is a matrix, then stem plots
all elements in a row against the same x value,
and the x-axis scale ranges from 1 to the number
of rows in Y.

stem(X,Y) plots
the data sequence, Y, at values specified by X.
The X and Y inputs must be vectors
or matrices of the same size. Additionally, X can
be a row or column vector and Y must be a matrix
with length(X) rows.

If X and Y are
both vectors, then stem plots entries in Y against
corresponding entries in X.

If X is a vector and Y is
a matrix, then stem plots each column of Y against
the set of values specified by X, such that all
elements in a row of Y are plotted against the
same value.

If X and Y are
both matrices, then stem plots columns of Y against
corresponding columns of X.

stem(axes_handle,___) plots
into the axes specified by axes_handle instead
of into the current axes (gca). The option, axes_handle,
can precede any of the input argument combinations in the previous
syntaxes.

h = stem(___) returns
a vector of stemseries object handles in h. When
multiple stemseries objects are present, you can make changes to properties
of a specific stemseries by specifying a particular handle.

Create a stem plot of 50 data values between
and
.

figure
Y = linspace(-2*pi,2*pi,50);
stem(Y)

Data values are plotted as stems extending from the baseline and terminating at the data value. The length of Y automatically determines the position of each stem on the x-axis.

figure
X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
stem(Y)

Each column of Y is plotted as a separate series, and entries in the same row of Y are plotted against the same x value. The number of rows in Y automatically generates the position of each stem on the x-axis.

Create a stem plot and set the line style to a dot-dashed line, the marker face color to red, and the marker edge color to green using Name,Value pair arguments.

figure
X = linspace(0,2*pi,25)';
Y = (cos(2*X));
stem(X,Y,'LineStyle','-.',...'MarkerFaceColor','red',...'MarkerEdgeColor','green')

Create a figure with two subplots and return the handles to each axes, s(1) and s(2). Create a stem plot in the lower subplot by referring to its axes handle, s(2).

figure
s(1) = subplot(2,1,1);
s(2) = subplot(2,1,2);
X = 0:25;
Y = [exp(0.1*X); -exp(.05*X)]';
stem(s(2),X,Y)

Data sequence to display, specified as a vector
or matrix. When Y is a vector, stem creates
one stemseries. When Y is a matrix, stem creates
a separate stemseries for each column.

Locations to plot data values in Y, specified
as a vector or matrix. When Y is a vector, X must
be a vector of the same size. When Y is a matrix, X must
be a matrix of the same size, or a vector whose length equals the
number of rows in Y.

Axes handle, which is the reference to an axes object. Use the gca function
to get the handle to the current axes, for example, axes_handle
= gca;.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument
name and Value is the corresponding
value. Name must appear
inside single quotes (' ').
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'LineStyle',':','MarkerFaceColor','red' plots
the stem as a dotted line and colors the marker face red.

For more information on these properties see stemseries.

Line width, specified as the comma-separated pair consisting
of 'LineWidth' and a scalar. The scalar sets the
width size in points of the stem and marker edge.

Color, specified as the comma-separated pair consisting of 'Color' and
a three-element RGB vector or a string containing the short or long
name of the color. The RGB vector is a three-element row vector whose
elements specify the intensities of the red, green, and blue components
of the color. The intensities must be in the range [0 1].

This table lists the predefined colors and their RGB equivalents.

Marker edge color, specified as the comma-separated pair consisting
of 'MarkerEdgeColor' and a color value. The color
value can be one of the supported strings or an RGB vector, listed
in the following tables.

Specifier

Result

'auto'

Uses same color as line color

'none'

Specifies no color, which makes unfilled markers invisible

For an RGB vector, use a three-element row vector whose elements
specify the intensities of the red, green, and blue components of
the color. The intensities must be in the range [0 1].
This table lists the predefined string colors and their RGB equivalents.

Marker face color, specified as the comma-separated pair consisting
of 'MarkerFaceColor' and a color value. MarkerFaceColor sets
the fill color for markers that are closed shapes (circle, square,
diamond, pentagram, hexagram, and the four triangles). The color value
can be one of the supported strings or an RGB vector, listed in the
following tables.

Specifier

Result

'auto'

Uses same color as marker edge color

'none'

Makes the interior of the marker transparent, allowing
the background to show through (default)

For an RGB vector, use a three-element row vector whose elements
specify the intensities of the red, green, and blue components of
the color. The intensities must be in the range [0 1].
This table lists the predefined string colors and their RGB equivalents.

Stemseries object handle, returned as a scalar or column vector.
This is a unique identifier, which you can use to query and modify
the properties of a specific stemseries.