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(ax,___) plots
into the axes specified by ax instead of into the
current axes (gca). The option, ax,
can precede any of the input argument combinations in the previous
syntaxes.

h = stem(___) returns
a vector of stem series handles in h. When multiple
stem series are present, you can make changes to properties of a specific
stem series 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)

Create a stem plot and return the two stem series handles.

figure
X = 0:25;
Y = [cos(X); exp(0.05*X)]';
h = stem(X,Y);

The stem function creates a stem series for each column of data. The output argument, h, contains the stem series handles.

Use the handle of the first stem series, h(1), to set its color to green. Use the handle of the second stem series, h(2), to change its markers to squares. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

Create a stem plot and change properties of the baseline.

figure
X = linspace(0,2*pi,50);
Y = exp(0.3*X).*sin(3*X);
h = stem(X,Y);

Change the line style of the baseline. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use the set function instead.

hbase = h.BaseLine;
hbase.LineStyle = '--';

Hide the baseline by setting its Visible property to 'off' .

Data sequence to display, specified as a vector or matrix. When Y is
a vector, stem creates one stem series. When Y is
a matrix, stem creates a separate stem series 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 object. Use ax to modify the stem series
after it is created.

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.

The stem series properties listed here are only
a subset. For a complete list, see Stem Series Properties.

Stem color, specified as an RGB triplet, a color string, or 'none'.
If you specify the Color as 'none',
then the stems are invisible.

An RGB triplet 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],
for example, [0.4 0.6 0.7]. This table lists RGB
triplet values that have equivalent color strings.

Marker outline color, specified as one of these values:

'auto' — Use the same color
as the Color property.

'none' — Use no color, which
makes unfilled markers invisible.

RGB triplet or color string — Use the specified
color.

An RGB triplet 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],
for example, [0.4 0.6 0.7]. This table lists RGB
triplet values that have equivalent color strings.

Marker fill color, specified as one of these values:

'none' — Use no color, which
makes the interior invisible.

'auto' — Use the same color
as the Color property
for the axes.

RGB triplet or color string — Use the specified
color.

An RGB triplet 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],
for example, [0.4 0.6 0.7]. This table lists RGB
triplet values that have equivalent color strings.

Stem series objects, returned as a scalar or column vector.
This is a unique identifier, which you can use to modify the properties
of a specific stem series after it is created.