Plot 3-D discrete sequence data (2024)

Table of Contents
Syntax Description Vector and Matrix Data Table Data Additional Options Examples Row Vector Input Column Vector Input Matrix Input Specify Stem Locations with Vector Inputs Specify Stem Locations with Matrix Inputs Fill in Markers Line Style, Marker Symbol, and Color Options Line Style, Marker Symbol, and Color Options Additional Style Options Plot Data from a Table Stem Plot in Specific Axes Modify Stem Series After Creation Input Arguments Z — Data sequence to display vector or matrix X — Locations to plot values of Z vector or matrix Y — Locations to plot values of Z vector or matrix LineSpec — Line style, marker, and color string scalar | character vector tbl — Source table table | timetable zvar — Table variable containing z-coordinatesstring scalar | character vector | pattern | numeric scalar | logical vector | vartype() xvar — Table variable containing x-coordinates string scalar | character vector | pattern | numeric scalar | logical vector | vartype() yvar — Table variable containing y-coordinates string scalar | character vector | pattern | numeric scalar | logical vector | vartype() ax — Axes object Axes object Name-Value Arguments LineWidth — Line width of stem and marker edge 0.5 (default) | positive value Color — Stem color [0 0 0] (default) | RGB triplet | hexadecimal color code | "r" | "g" | "b" | ... Marker — Marker symbol "o" (default) | "+" | "*" | "." | "x" | ... Output Arguments h — Stem object Stem Extended Capabilities GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™. Distributed ArraysPartition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™. Version History R2022b: Expanded data type support R2022b: Pass tables directly to stem3 See Also Functions Properties Topics MATLAB Command Americas Europe Asia Pacific

Plot 3-D discrete sequence data

collapse all in page

  • Plot 3-D discrete sequence data (1)

Syntax

stem3(Z)

stem3(X,Y,Z)

stem3(___,"filled")

stem3(___,LineSpec)

stem3(tbl,xvar,yvar,zvar)

stem3(___,Name,Value)

stem3(ax,___)

h = stem3(___)

Description

Vector and Matrix Data

example

stem3(Z) plots entriesin Z as stems extending from the xy-planeand terminating with circles at the entry values. The stem locationsin the xy-plane are automatically generated.

example

stem3(X,Y,Z) plotsentries in Z as stems extending from the xy-planewhere X and Y specify the stemlocations in the xy-plane. The inputs X, Y,and Z must be vectors or matrices of the same size.

example

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

example

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

Table Data

example

stem3(tbl,xvar,yvar,zvar) plots the variables xvar, yvar, and zvar from the table tbl. Specify one table variable for each dimension. (since R2022b)

Additional Options

example

stem3(___,Name,Value) modifies the stem chart using one or more name-value pair arguments.

example

stem3(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 = stem3(___) returnsthe Stem object h.

Examples

collapse all

Row Vector Input

Open Live Script

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

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

Plot 3-D discrete sequence data (2)

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

Column Vector Input

Open Live Script

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

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

Plot 3-D discrete sequence data (3)

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

Matrix Input

Open Live Script

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

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

Plot 3-D discrete sequence data (4)

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.

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

Plot 3-D discrete sequence data (5)

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

Specify Stem Locations with Matrix Inputs

Open Live Script

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)

Plot 3-D discrete sequence data (6)

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

Fill in Markers

Open Live Script

Create a 3-D stem plot of cosine values between -π and π and fill in the markers.

X = linspace(-pi,pi,40);Z = cos(X);stem3(Z,'filled')

Plot 3-D discrete sequence data (7)

Line Style, Marker Symbol, and Color Options

Open Live Script

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

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

Plot 3-D discrete sequence data (8)

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

Line Style, Marker Symbol, and Color Options

Open Live Script

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

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

Plot 3-D discrete sequence data (9)

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

Additional Style Options

Open Live Script

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

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

Plot 3-D discrete sequence data (10)

Plot Data from a Table

Open Live Script

Since R2022b

A convenient way to plot data from a table is to pass the table to the stem3 function and specify the variables to plot.

Read weather.csv as a timetable tbl. Then display the first three rows of the table.

tbl = readtimetable("weather.csv");head(tbl,3)
 Time WindDirection WindSpeed Humidity Temperature RainInchesPerMinute CumulativeRainfall PressureHg PowerLevel LightIntensity ____________________ _____________ _________ ________ ___________ ___________________ __________________ __________ __________ ______________ 25-Oct-2021 00:00:09 46 1 84 49.2 0 0 29.96 4.14 0 25-Oct-2021 00:01:09 45 1.6 84 49.2 0 0 29.96 4.139 0 25-Oct-2021 00:02:09 36 2.2 84 49.2 0 0 29.96 4.138 0 

Plot the Time variable on the x-axis, the Temperature variable on the y-axis, and the CumulativeRainfall variable on the z-axis. Return the Stem object as h. Notice that the axis labels match the table variable names.

h = stem3(tbl,"Time","Temperature","CumulativeRainfall");

Plot 3-D discrete sequence data (11)

Change the color of the plot to a shade of red by setting the Color property.

h.Color = [0.7 0 0.2];

Plot 3-D discrete sequence data (12)

Stem Plot in Specific Axes

Open Live Script

Since R2019b

You can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Create separate stem plots in the axes by specifying the axes object as the first argument to stem3.

X = linspace(-2,2,50);Y = X.^3;Z = exp(X);tiledlayout(2,1)% Top plotax1 = nexttile;stem(ax1,X,Z)% Bottom plotax2 = nexttile; stem3(ax2,X,Y,Z)

Plot 3-D discrete sequence data (13)

Modify Stem Series After Creation

Open Live Script

Create a 3-D stem plot and return the stem series object.

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

Plot 3-D discrete sequence data (14)

Change the color to magenta and set the marker face color to yellow. Use view to adjust the angle of the axes in the figure. Use dot notation to set properties.

h.Color = 'm';h.MarkerFaceColor = 'y';view(-10,35)

Plot 3-D discrete sequence data (15)

Input Arguments

collapse all

ZData sequence to display
vector or matrix

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

  • If Z is a row vector, stem3 plotsall elements against the same y value at equallyspaced x values.

  • If Z is a column vector, stem3 plotsall elements against the same x value at equallyspaced y values.

  • If Z is a matrix, stem3 plotseach row of Z against the same y valueat equally spaced x values.

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

XLocations to plot values of Z
vector 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 | categorical | datetime | duration

YLocations to plot values of Z
vector or matrix

Locations to plot values of Z, specifiedas a vector or a matrix. Inputs X, Y and Z mustbe vectors or matrices of the same size.

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

LineSpecLine style, marker, and color
string scalar | character vector

Line style, marker, and color, specified as a string scalar or character vector containing symbols. The symbols can appear in any order. You do not need to specify all three characteristics (line style, marker, and color). For example, if you omit the line style and specify the marker, then the plot shows only the marker and no line.

Example: "--or" is a red dashed line with circle markers.

Line StyleDescriptionResulting Line
"-"Solid line

Plot 3-D discrete sequence data (16)

"--"Dashed line

Plot 3-D discrete sequence data (17)

":"Dotted line

Plot 3-D discrete sequence data (18)

"-."Dash-dotted line

Plot 3-D discrete sequence data (19)

MarkerDescriptionResulting Marker
"o"Circle

Plot 3-D discrete sequence data (20)

"+"Plus sign

Plot 3-D discrete sequence data (21)

"*"Asterisk

Plot 3-D discrete sequence data (22)

"."Point

Plot 3-D discrete sequence data (23)

"x"Cross

Plot 3-D discrete sequence data (24)

"_"Horizontal line

Plot 3-D discrete sequence data (25)

"|"Vertical line

Plot 3-D discrete sequence data (26)

"square"Square

Plot 3-D discrete sequence data (27)

"diamond"Diamond

Plot 3-D discrete sequence data (28)

"^"Upward-pointing triangle

Plot 3-D discrete sequence data (29)

"v"Downward-pointing triangle

Plot 3-D discrete sequence data (30)

">"Right-pointing triangle

Plot 3-D discrete sequence data (31)

"<"Left-pointing triangle

Plot 3-D discrete sequence data (32)

"pentagram"Pentagram

Plot 3-D discrete sequence data (33)

"hexagram"Hexagram

Plot 3-D discrete sequence data (34)

Color NameShort NameRGB TripletAppearance
"red""r"[1 0 0]

Plot 3-D discrete sequence data (35)

"green""g"[0 1 0]

Plot 3-D discrete sequence data (36)

"blue""b"[0 0 1]

Plot 3-D discrete sequence data (37)

"cyan" "c"[0 1 1]

Plot 3-D discrete sequence data (38)

"magenta""m"[1 0 1]

Plot 3-D discrete sequence data (39)

"yellow""y"[1 1 0]

Plot 3-D discrete sequence data (40)

"black""k"[0 0 0]

Plot 3-D discrete sequence data (41)

"white""w"[1 1 1]

Plot 3-D discrete sequence data (42)

tblSource table
table | timetable

Source table containing the data to plot, specified as a table or a timetable.

zvarTable variable containing z-coordinates
string scalar | character vector | pattern | numeric scalar | logical vector | vartype()

Table variable containing the z-coordinates, specified using one of the indexing schemes from the table. Specify one variable only.

Indexing SchemeExamples

Variable name:

  • A string scalar or character vector.

  • A pattern object. The pattern object must refer to only one variable.

  • "A" or 'A' — A variable named A

  • "Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit

Variable index:

  • An index number that refers to the location of a variable in the table.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable.

  • vartype("double") — The variable containing double values

The table variable you specify can contain numeric, logical, categorical, datetime, or duration values.

Example: stem3(tbl,"x","y","z") specifies the table variable named z for the z-coordinates.

xvarTable variable containing x-coordinates
string scalar | character vector | pattern | numeric scalar | logical vector | vartype()

Table variable containing the x-coordinates, specified using one of the indexing schemes from the table. Specify one variable only.

Indexing SchemeExamples

Variable name:

  • A string scalar or character vector.

  • A pattern object. The pattern object must refer to only one variable.

  • "A" or 'A' — A variable named A

  • "Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit

Variable index:

  • An index number that refers to the location of a variable in the table.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable.

  • vartype("double") — The variable containing double values

The table variable you specify can contain numeric, logical, categorical, datetime, or duration values.

Example: stem3(tbl,"x","y","z") specifies the table variable named x for the x-coordinates.

yvarTable variable containing y-coordinates
string scalar | character vector | pattern | numeric scalar | logical vector | vartype()

Table variable containing the y-coordinates, specified using one of the indexing schemes from the table. Specify one variable only.

Indexing SchemeExamples

Variable name:

  • A string scalar or character vector.

  • A pattern object. The pattern object must refer to only one variable.

  • "A" or 'A' — A variable named A

  • "Var"+digitsPattern(1) — The variable with the name "Var" followed by a single digit

Variable index:

  • An index number that refers to the location of a variable in the table.

  • A logical vector. Typically, this vector is the same length as the number of variables, but you can omit trailing 0 or false values.

  • 3 — The third variable from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects a table variable of a specified type. The subscript must refer to only one variable.

  • vartype("double") — The variable containing double values

The table variable you specify can contain numeric, logical, categorical, datetime, or duration values.

Example: stem3(tbl,"x","y","z") specifies the table variable named y for the y-coordinates.

axAxes object
Axes object

Axes object. If you do not specify the axes, then stem plots into the current axes.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "LineStyle",":","MarkerFaceColor","red" plots the stem as a dotted line and sets the marker face color to red.

The properties listed here are only a subset. For a completelist, see Stem Properties.

LineWidthLine width of stem and marker edge
0.5 (default) | positive value

Line width of stem and marker edge, specified as a positivevalue in point units.

Example: 0.75

ColorStem color
[0 0 0] (default) | RGB triplet | hexadecimal color code | "r" | "g" | "b" | ...

Stem color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • 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].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Plot 3-D discrete sequence data (43)

"green""g"[0 1 0]"#00FF00"

Plot 3-D discrete sequence data (44)

"blue""b"[0 0 1]"#0000FF"

Plot 3-D discrete sequence data (45)

"cyan" "c"[0 1 1]"#00FFFF"

Plot 3-D discrete sequence data (46)

"magenta""m"[1 0 1]"#FF00FF"

Plot 3-D discrete sequence data (47)

"yellow""y"[1 1 0]"#FFFF00"

Plot 3-D discrete sequence data (48)

"black""k"[0 0 0]"#000000"

Plot 3-D discrete sequence data (49)

"white""w"[1 1 1]"#FFFFFF"

Plot 3-D discrete sequence data (50)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Plot 3-D discrete sequence data (51)

[0.8500 0.3250 0.0980]"#D95319"

Plot 3-D discrete sequence data (52)

[0.9290 0.6940 0.1250]"#EDB120"

Plot 3-D discrete sequence data (53)

[0.4940 0.1840 0.5560]"#7E2F8E"

Plot 3-D discrete sequence data (54)

[0.4660 0.6740 0.1880]"#77AC30"

Plot 3-D discrete sequence data (55)

[0.3010 0.7450 0.9330]"#4DBEEE"

Plot 3-D discrete sequence data (56)

[0.6350 0.0780 0.1840]"#A2142F"

Plot 3-D discrete sequence data (57)

Example: "blue"

Example: [00 1]

Example: "#0000FF"

MarkerMarker symbol
"o" (default) | "+" | "*" | "." | "x" | ...

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

MarkerDescriptionResulting Marker
"o"Circle

Plot 3-D discrete sequence data (58)

"+"Plus sign

Plot 3-D discrete sequence data (59)

"*"Asterisk

Plot 3-D discrete sequence data (60)

"."Point

Plot 3-D discrete sequence data (61)

"x"Cross

Plot 3-D discrete sequence data (62)

"_"Horizontal line

Plot 3-D discrete sequence data (63)

"|"Vertical line

Plot 3-D discrete sequence data (64)

"square"Square

Plot 3-D discrete sequence data (65)

"diamond"Diamond

Plot 3-D discrete sequence data (66)

"^"Upward-pointing triangle

Plot 3-D discrete sequence data (67)

"v"Downward-pointing triangle

Plot 3-D discrete sequence data (68)

">"Right-pointing triangle

Plot 3-D discrete sequence data (69)

"<"Left-pointing triangle

Plot 3-D discrete sequence data (70)

"pentagram"Pentagram

Plot 3-D discrete sequence data (71)

"hexagram"Hexagram

Plot 3-D discrete sequence data (72)

"none"No markersNot applicable

Example: "+"

Example: "diamond"

Output Arguments

collapse all

hStem object
Stem

Stem object. This is a unique identifier, whichyou can use to modify the properties of the Stem objectafter it is created.

Extended Capabilities

Version History

Introduced before R2006a

expand all

The x, y, and z input arguments can be any numeric, logical, datetime, duration, or categorical values. In previous releases, only numeric and logical values were supported.

Create plots by passing a table to the stem3 function followed by the variables you want to plot. When you specify your data as a table, the axis labels and the legend (if present) are automatically labeled using the table variable names.

See Also

Functions

  • bar | plot | stairs | stem

Properties

  • Stem Properties

Topics

  • Combine Line and Stem Plots
  • Plots That Support Tables

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Plot 3-D discrete sequence data (73)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Plot 3-D discrete sequence data (2024)
Top Articles
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 6423

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.