Skip to Main Content Skip to Search
Product Documentation

stem - Plot discrete sequence data

Example of stem function output

Alternatives

To graph selected variables, use the Plot Selector in the Workspace Browser, or use the Figure Palette Plot Catalog. Manipulate graphs in plot edit mode with the Property Editor. For details, see Plotting Tools — Interactive Plotting in the MATLAB Graphics documentation and Creating Graphics from the Workspace Browser in the MATLAB Desktop Tools documentation.

Syntax

stem(Y)
stem(X,Y)
stem(...,'fill')
stem(...,LineSpec)
stem(...,'PropertyName',PropertyValue,...)
stem(axes_handle,...)
h = stem(...)

Description

A two-dimensional stem plot displays data as lines extending from a baseline along the x-axis. A circle (the default) or other marker whose y-position represents the data value terminates each stem.

stem(Y) plots the data sequence Y as stems that extend from equally spaced and automatically generated values along the x-axis. When Y is a matrix, stem plots all elements in a row against the same x value.

stem(X,Y) plots X versus the columns of Y. X and Y must be vectors or matrices of the same size. Additionally, X can be a row or a column vector and Y a matrix with length(X) rows.

stem(...,'fill') specifies whether to color the circle at the end of the stem.

stem(...,LineSpec) specifies the line style, marker symbol, and color for the stem and top marker (the baseline is not affected). See LineSpec for more information.

stem(...,'PropertyName',PropertyValue,...) specifies property name and property value pairs for the stemseries objects the function creates.

stem(axes_handle,...) plots into the axes object with the handle axes_handle instead of into the current axes object (gca).

h = stem(...) returns a vector of stemseries object handles in h, one handle per column of data in Y.

Examples

Single Series of Data

This example creates a stem plot representing the cosine of 10 values linearly spaced between 0 and 2π. Note that the line style of the baseline is set by first getting its handle from the stemseries object's BaseLine property.

figure
t = linspace(-2*pi,2*pi,10);
h = stem(t,cos(t),'fill','--');
set(get(h,'BaseLine'),'LineStyle',':')
set(h,'MarkerFaceColor','red')

If you do not want the baseline to show, you can make the baseline invisible:

set(get(h,'Baseline'),'Visble','off')

where h is the stemseries handle returned by the stem function.

Delete the baseline with this command:

delete(get(h,'Baseline'))

Use similar code to change the color or style of the baseline, specifying any line property and value, for example,

set(get(h,'Baseline'),'LineWidth',3)

Two Series of Data on One Graph

This example creates a stem plot from a two-column matrix. In this case, the stem function creates two stemseries objects, one for each column of data. Both objects' handles are returned in the output argument h.

See Also

bar | plot | stairs | Stemseries Properties

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS