Navigation

Operators and Keywords

Function List:

C++ API

: stem (y)
: stem (x, y)
: stem (…, linespec)
: stem (…, "filled")
: stem (…, prop, val, …)
: stem (hax, …)
: h = stem (…)

Plot a 2-D stem graph.

If only one argument is given, it is taken as the y-values and the x-coordinates are taken from the indices of the elements.

If y is a matrix, then each column of the matrix is plotted as a separate stem graph. In this case x can either be a vector, the same length as the number of rows in y, or it can be a matrix of the same size as y.

The default color is "b" (blue), the default line style is "-", and the default marker is "o". The line style can be altered by the linespec argument in the same manner as the plot command. If the "filled" argument is present the markers at the top of the stems will be filled in. For example,

x = 1:10;
y = 2*x;
stem (x, y, "r");

plots 10 stems with heights from 2 to 20 in red;

Optional property/value pairs may be specified to control the appearance of the plot.

If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca.

The optional return value h is a handle to a "stem series" hggroup. The single hggroup handle has all of the graphical elements comprising the plot as its children; This allows the properties of multiple graphics objects to be changed by modifying just a single property of the "stem series" hggroup.

For example,

x = [0:10]';
y = [sin(x), cos(x)]
h = stem (x, y);
set (h(2), "color", "g");
set (h(1), "basevalue", -1)

changes the color of the second "stem series" and moves the base line of the first.

Stem Series Properties

linestyle

The linestyle of the stem. (Default: "-")

linewidth

The width of the stem. (Default: 0.5)

color

The color of the stem, and if not separately specified, the marker. (Default: "b" [blue])

marker

The marker symbol to use at the top of each stem. (Default: "o")

markeredgecolor

The edge color of the marker. (Default: "color" property)

markerfacecolor

The color to use for "filling" the marker. (Default: "none" [unfilled])

markersize

The size of the marker. (Default: 6)

baseline

The handle of the line object which implements the baseline. Use set with the returned handle to change graphic properties of the baseline.

basevalue

The y-value where the baseline is drawn. (Default: 0)

See also: stem3, bar, hist, plot, stairs.

Demonstration 1

The following code

 clf;
 y = 1:10;
 stem (y);
 title ("stem plot of y-values only");

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 x = 1:10;
 y = 2*x;
 stem (x, y);
 title ("stem plot of x and y-values");

Produces the following figure

Figure 1

Demonstration 3

The following code

 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, "r");
 title ("stem plot with modified color");

Produces the following figure

Figure 1

Demonstration 4

The following code

 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, "-.k");
 title ("stem plot with modified line style and color");

Produces the following figure

Figure 1

Demonstration 5

The following code

 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, "-.ks");
 title ("stem plot with modified line style, color, and marker");

Produces the following figure

Figure 1

Demonstration 6

The following code

 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, "filled");
 title ('stem plot with "filled" markers');

Produces the following figure

Figure 1

Demonstration 7

The following code

 clf;
 x = 1:10;
 y = 2*x;
 h = stem (x, y, "markerfacecolor", [1 0 1]);
 title ("stem plot modified with property/value pair");

Produces the following figure

Figure 1

Demonstration 8

The following code

 clf;
 x = (0 : 10)';
 y = [sin(x), cos(x)];
 h = stem (x, y);
 set (h(2), "color", "g");
 set (h(1), "basevalue", -0.75);
 title ("stem plots modified through hggroup handle");

Produces the following figure

Figure 1

Demonstration 9

The following code

 clf;
 N = 11;
 x = 0:(N-1);
 y = rand (1, N);
 hs = stem (x(1), y(1));
 set (gca (), "xlim", [1, N-1], "ylim", [0, 1]);
 title ("stem plot data modified through hggroup handle");
 for k=2:N
   set (hs, "xdata", x(1:k), "ydata", y(1:k));
   drawnow ();
   pause (0.2);
 endfor

Produces the following figure

Figure 1

Package: octave