Accelerating the pace of engineering and science

Documentation Center

• Trial Software

stem3

Plot 3-D discrete sequence data

Description

example

stem3(Z) plots entries in Z as stems extending from the xy-plane and terminating with circles at the entry values. The stem locations in the xy-plane are automatically generated.

example

stem3(X,Y,Z) plots entries in Z as stems extending from the xy-plane where X and Y specify the stem locations in the xy-plane. The inputs X, Y, and Z must be vectors or matrices of the same size.

example

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

example

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

example

stem3(___,Name,Value) specifies stemseries properties using one or more Name,Value pair arguments.

example

stem3(axes_handle,___) plots into the axes specified by axes_handle instead of into the current axes (gca). The option, axes_handle, can precede any of the input argument combinations in the previous syntaxes.

example

h = stem3(___) returns the stemseries handle h.

Examples

expand all

Row Vector Input

Create a 3-D stem plot of cosine values between -π/2 and π/2 with a row vector input.

```figure
X = linspace(-pi/2,pi/2,40);
Z = cos(X);
stem3(Z)```

stem3 plots elements of Z against the same y value at equally space x values.

Column Vector Input

Create a 3-D stem plot of cosine values between -π/2 and π/2 with a column vector input.

```figure
X = linspace(-pi/2,pi/2,40)';
Z = cos(X);
stem3(Z)```

stem3 plots elements of Z against the same x value at equally space y values.

Matrix Input

Create a 3-D stem plot of sine and cosine values between -π/2 and π/2 with a matrix input.

```figure
X = linspace(-pi/2,pi/2,40);
Z = [sin(X); cos(X)];
stem3(Z)```

stem3 plots each row of Z against the same y value at equally space x values.

Specify Stem Locations with Vector Inputs

Create a 3-D stem plot and specify the stem locations along a curve. Use view to adjust the angle of the axes in the figure.

```figure
X = linspace(-5,5,60);
Y = cos(X);
Z = X.^2;
stem3(X,Y,Z)
view(-8,30)```

X and Y determine the stem locations. Z determines the marker heights.

Specify Stem Locations with Matrix Inputs

Create a 3-D stem plot with matrix data and specify the stem locations in the xy-plane.

```figure
[X,Y] = meshgrid(0:.1:1);
Z = exp(X+Y);
stem3(X,Y,Z)```

X and Y determine the stem locations. Z determines the marker heights.

Fill in the Circles

Create a 3-D stem plot of cosine values between -π and π. Use 'fill' to fill in the circles.

```figure
X = linspace(-pi,pi,40);
Z = cos(X);
stem3(Z,'fill')```

Line Style, Marker Symbol, and Color Options

Create a 3-D stem plot of cosine values between -π and π. Set the stem to a dashed line style, the marker symbols to stars, and the color to magenta using LineSpec.

```figure
X = linspace(-pi,pi,40);
Z = cos(X);
stem3(Z,'--*m')```

To specify only two of the three LineSpec options, omit the third option from the string. For example,'*m' sets the marker symbol and the color and leaves the default line style.

Line Style, Marker Symbol, and Color Options

Create a 3-D stem plot and specify the stem locations along a circle. Set the stem to a dashed line style, the marker symbols to stars, and the color to magenta using LineSpec.

```figure
theta = linspace(0,2*pi);
X = cos(theta);
Y = sin(theta);
Z = theta;
stem3(X,Y,Z,':.m')```

X and Y determine the stem locations. Z determines the marker heights.

Create a 3-D stem plot of cosine values between -π and π. Set the marker symbols to squares with green faces and magenta edges.

```figure
X = linspace(-pi,pi,40);
Z = cos(X);
stem3(Z,'Marker','s','MarkerEdgeColor','m','MarkerFaceColor','g')```

Axes Handles

Specify an axes for the 3-D stem plot.

Create two subplots and return the handles to each axes, s(1) and s(2).

```figure
s(1) = subplot(2,1,1);
s(2) = subplot(2,1,2);```

Define vectors X, Y and Z.

```X = linspace(-2,2,50);
Y = X.^3;
Z = exp(X);```

Plot a 3-D stem plot in the lower subplot using the axes handle s(2). Adjust the angle of the axes using view. For comparison, plot a 2-D stem plot in the upper subplot using X and Z.

```stem(s(1),X,Z)
stem3(s(2),X,Y,Z)
view(-20,35)```

Stemseries Handle

Create a 3-D stem plot and use the stemseries handle to adjust properties of the plot.

Get the handle for the stemseries.

```figure
X = linspace(0,2);
Y = X.^3;
Z = exp(X).*cos(Y);
h = stem3(X,Y,Z,'fill');  ```

Set the color to magenta and the marker face color to yellow. Use view to adjust the angle of the axes in the figure.

```set(h,'Color','m','MarkerFaceColor','y');
view(-10,35)```

Input Arguments

expand all

Z — Data sequence to displayvector or matrix

Data sequence to display, specified as a vector or matrix. stem3 plots each element in Z as a stem extending from the xy-plane and terminating at the data value.

• If Z is a row vector, stem3 plots all elements against the same y value at equally spaced x values.

• If Z is a column vector, stem3 plots all elements against the same x value at equally spaced y values.

• If Z is a matrix, stem3 plots each row of Z against the same y value at equally spaced x values.

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

X — Locations to plot values of Zvector or matrix

Locations to plot values ofZ, specified as a vector or a matrix. Inputs X, Y and Z must be vectors or matrices of the same size.

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

Y — Locations to plot values of Zvector or matrix

Locations to plot values of Z, specified as a vector or a matrix. Inputs X, Y and Z must be vectors or matrices of the same size.

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

LineSpec — Line style, marker symbol, and colorstring

Line style, marker symbol, and color, specified as a string. For more information on line style, marker symbol, and color options see LineSpec.

Example: ':*r'

Data Types: char

axes_handle — Axes handlehandle

Axes handle, which is the reference to an axes object. Use the gca function to get the handle to the current axes, for example, axes_handle = gca;.

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 sets the marker face color to red.

'LineStyle' — Line style'-' (default) | '--' | ':' | '-.' | 'none'

Line style, specified as the comma-separated pair consisting of 'LineStyle' and a line style specifier. This table lists supported line styles.

Specifier

Line Style

'- '

Solid line (default)

'--'

Dashed line

':'

Dotted line

'-. '

Dash-dot line

'none'

No line

Example: 'LineStyle','-.'

'LineWidth' — Line width0.5 (default) | scalar

Line width, specified as the comma-separated pair consisting of 'LineWidth' and a scalar. The scalar sets the width size in points of the stem and marker edge.

Example: 'LineWidth',0.75

'Color' — Color[0 0 1] (blue) (default) | three-element RGB vector | string

Color, specified as the comma-separated pair consisting of 'Color' and a three-element RGB vector or a string containing the short or long name of the color. The RGB vector 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].

This table lists the predefined colors and their RGB equivalents.

RGB Vector

Short Name

Long Name

[1 1 0]

'y'

'yellow'

[1 0 1]

'm'

'magenta'

[0 1 1]

'c'

'cyan'

[1 0 0]

'r'

'red'

[0 1 0]

'g'

'green'

[0 0 1]

'b'

'blue'

[1 1 1]

'w'

'white'

[0 0 0]

'k'

'black'

Example: 'Color',[0 1 0]

Example: 'Color','green'

Example: 'Color','g'

'Marker' — Marker symbol'o' (default) | string

Marker symbol, specified as the comma-separated pair consisting of 'Marker' and a marker specifier. This table lists supported marker symbols.

Specifier

Marker Symbol

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

Example: 'Marker','+'

Example: 'Marker','diamond'

'MarkerEdgeColor' — Marker edge color[0 0 1] (blue) (default) | 'auto' | 'none' | three-element RGB vector | string

Marker edge color, specified as the comma-separated pair consisting of 'MarkerEdgeColor' and a color value. The color value can be one of the supported strings or an RGB vector, listed in the following tables.

Specifier

Result

'auto'

Uses same color as line color

'none'

Specifies no color, which makes unfilled markers invisible

For an RGB vector, use 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]. This table lists the predefined string colors and their RGB equivalents.

RGB Vector

Short Name

Long Name

[1 1 0]

'y'

'yellow'

[1 0 1]

'm'

'magenta'

[0 1 1]

'c'

'cyan'

[1 0 0]

'r'

'red'

[0 1 0]

'g'

'green'

[0 0 1]

'b'

'blue'

[1 1 1]

'w'

'white'

[0 0 0]

'k'

'black'

Example: 'MarkerEdgeColor',[1 .8 .1]

'MarkerFaceColor' — Marker face color'none' (default) | 'auto' | three-element RGB vector | string

Marker face color, specified as the comma-separated pair consisting of 'MarkerFaceColor' and a color value. MarkerFaceColor sets the fill color for markers that are closed shapes (circle, square, diamond, pentagram, hexagram, and the four triangles). The color value can be one of the supported strings or an RGB vector, listed in the following tables.

Specifier

Result

'auto'

Uses same color as marker edge color

'none'

Makes the interior of the marker transparent, allowing the background to show through (default)

For an RGB vector, use 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]. This table lists the predefined string colors and their RGB equivalents.

RGB Vector

Short Name

Long Name

[1 1 0]

'y'

'yellow'

[1 0 1]

'm'

'magenta'

[0 1 1]

'c'

'cyan'

[1 0 0]

'r'

'red'

[0 1 0]

'g'

'green'

[0 0 1]

'b'

'blue'

[1 1 1]

'w'

'white'

[0 0 0]

'k'

'black'

Example: 'MarkerFaceColor',[0 .8 1]

'MarkerSize' — Marker size6 (default) | scalar

Marker size, specified as the comma-separated pair consisting of 'MarkerSize' and a scalar in points.

Example: 'Markersize',12

Output Arguments

expand all

h — Stemseries object handlescalar

Stemseries object handle, specified as a scalar. This is a unique identifier, which you can use to query and modify the properties of the stemseries.