| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
![]()
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.
stem(Y)
stem(X,Y)
stem(...,'fill')
stem(...,LineSpec)
stem(axes_handle,...)
h = stem(...)
hlines = stem('v6',...)
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(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.
hlines = stem('v6',...) returns the handles of line objects instead of stemseries objects for compatibility with MATLAB 6.5 and earlier.
hlines contains the handles to three line graphics objects:
hlines(1) — The marker symbol at the top of each stem
hlines(2) — The stem line
hlines(3) — The baseline handle
Note The v6 option enables users of Version 7.x of MATLAB to create FIG-files that previous versions can open. It is obsolete and will be removed in a future version of MATLAB. |
See Plot Objects and Backward Compatibility for more information.
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.
t = linspace(-2*pi,2*pi,10); h = stem(t,cos(t),'fill','--'); set(get(h,'BaseLine'),'LineStyle',':') set(h,'MarkerFaceColor','red')

The following diagram illustrates the parent-child relationship in the previous stem plot. Note that the stemseries object contains two line objects used to draw the stem lines and the end markers. The baseline is a separate line object.

If you do not want the baseline to show, you can remove it with the following command:
delete(get(stem_handle,'Baseline'))
where stem_handle is the handle for the stemseries object. You can use similar code to change the color or style of the baseline, specifying any line property and value, for example,
set(get(stem_handle,'Baseline'),'LineWidth',3)
The following example creates a stem plot from a two-column matrix. In this case, the stem function creates two stemseries objects, one of each column of data. Both objects' handles are returned in the output argument h.
h(1) is the handle to the stemseries object plotting the expression exp(-.07*x).*cos(x).
h(2) is the handle to the stemseries object plotting the expression exp(.05*x).*cos(x).
x = 0:25; y = [exp(-.07*x).*cos(x);exp(.05*x).*cos(x)]'; h = stem(x,y); set(h(1),'MarkerFaceColor','blue') set(h(2),'MarkerFaceColor','red','Marker','square')

The following diagram illustrates the parent-child relationship in the previous stem plot. Note that each column in the input matrix y results in the creation of a stemseries object, which contains two line objects (one for the stems and one for the markers). The baseline is shared by both stemseries objects.

Stemseries properties for property descriptions
![]() | std (timeseries) | stem3 | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |