Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

stem

Plot discrete sequence data

Syntax

Description

example

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.

example

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.

example

stem(___,'filled') fills the circles. Use this option with any of the input argument combinations in the previous syntaxes.

example

stem(___,LineSpec) specifies the line style, marker symbol, and color.

example

stem(___,Name,Value) specifies stem series properties using one or more Name,Value pair arguments.

example

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.

example

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.

Examples

collapse all

Create a stem plot of 50 data values between $-2\pi$ and $2\pi$.

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.

Plot two data series using a two-column matrix.

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.

Plot 50 data values of cosine evaluated between 0 and $2\pi$ and specify the set of x values for the stem plot.

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

The first vector input determines the position of each stem on the x-axis.

Plot 50 data values of sine and cosine evaluated between 0 and $2\pi$ and specify the set of x values for the stem plot.

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

The vector input determines the x-axis positions for both data series.

Plot 50 data values of sine and cosine evaluated at different sets of x values. Specify the corresponding sets of x values for each series.

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

Each column of X is plotted against the corresponding column of Y.

Create a stem plot and fill in the circles that terminate each stem.

X = linspace(0,10,20)';
Y = (exp(0.25*X));
stem(X,Y,'filled')

Create a stem plot and set the line style to a dotted line, the marker symbols to diamonds, and the color to red using the LineSpec option.

figure
X = linspace(0,2*pi,50)';
Y = (exp(X).*sin(X));
stem(X,Y,':diamondr')

To color the inside of the diamonds, use the 'fill' option.

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

The stem remains the default color.

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.

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

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

Set the first stem series color to green. Change the markers of the second stem series 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.

h(1).Color = 'green';
h(2).Marker = 'square';

Create a stem plot and change properties of the baseline.

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' .

hbase.Visible = 'off';

Create a stem plot with a baseline level at 2.

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

Related Examples

Input Arguments

collapse all

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.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | datetime | duration

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.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | datetime | duration

Line style, marker, and color, specified as a character vector of symbols. For more information, see LineSpec.

Example: ':*r'

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.

collapse all

Line style, specified as one of the line styles listed in this table.

Line StyleDescriptionResulting Line
'-'Solid line

'--'Dashed line

':'Dotted line

'-.'Dash-dotted line

'none'No lineNo line

Line width, specified as a positive value in points. If the line has markers, then the line width also affects the marker edges.

Example: 0.75

Stem color, specified as an RGB triplet, a character vector of color name, 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 the long and short color name options and the equivalent RGB triplet values.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black''k'[0 0 0]

Example: 'blue'

Example: [0 0 1]

Marker symbol, specified as one of the markers listed in this table.

ValueDescription
'o'Circle
'+'Plus sign
'*'Asterisk
'.'Point
'x'Cross
'square' or 's'Square
'diamond' or 'd'Diamond
'^'Upward-pointing triangle
'v'Downward-pointing triangle
'>'Right-pointing triangle
'<'Left-pointing triangle
'pentagram' or 'p'Five-pointed star (pentagram)
'hexagram' or 'h'Six-pointed star (hexagram)
'none'No markers

Example: '+'

Example: ‘diamond'

Marker size, specified as a positive value in points.

Example: 10

Marker outline color, specified as one of these values:

  • 'auto' — Use the same color specified in the Color property.

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

  • RGB triplet or character vector of a color name — 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 the long and short color name options and the equivalent RGB triplet values.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black''k'[0 0 0]

Example: [0.5 0.5 0.5]

Example: 'blue'

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 character vector of a color name — 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 the long and short color name options and the equivalent RGB triplet values.

Long NameShort NameRGB Triplet
'yellow''y'[1 1 0]
'magenta''m'[1 0 1]
'cyan''c'[0 1 1]
'red''r'[1 0 0]
'green''g'[0 1 0]
'blue''b'[0 0 1]
'white''w'[1 1 1]
'black''k'[0 0 0]

Example: [0.3 0.2 0.1]

Example: 'green'

Output Arguments

collapse all

Stem series objects, returned as a single object or an array of objects. These are unique identifiers, which you can use to modify the properties of a specific stem series after it is created.

See Also

Functions

Properties

Introduced before R2006a

Was this topic helpful?