3-D line plot - MATLAB plot3 (2024)

Table of Contents
Syntax Description Vector and Matrix Data Table Data Additional Options Examples Plot 3-D Helix Plot Multiple Lines Plot Multiple Lines Using Matrices Specify Equally-Spaced Tick Units and Axis Labels Plot Points as Markers Without Lines Customize Color and Marker Specify Line Style Modify Line After Plotting Plot Data from a Table Plot Multiple Table Variables on the x- and y-Axes Specify Target Axes Plot Duration Data with Custom Tick Format Plot Line With Marker at One Data Point Input Arguments X — x-coordinates scalar | vector | matrix Y — y-coordinates scalar | vector | matrix Z — z-coordinates scalar | vector | matrix LineSpec — Line style, marker, and color string scalar | character vector tbl — Source table table | timetable xvar — Table variables containing x-coordinatescharacter vector | string array | cell array | pattern | numeric scalar or vector | logical vector | vartype() yvar — Table variables containing y-coordinates character vector | string array | cell array | pattern | numeric scalar or vector | logical vector | vartype() zvar — Table variables containing z-coordinates character vector | string array | cell array | pattern | numeric scalar or vector | logical vector | vartype() ax — Target axes Axes object Name-Value Arguments Color — Color [0 0.4470 0.7410] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... Tips 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: Plots created with tables preserve special characters in axis and legend labels R2022a: Pass tables directly to plot3 See Also Functions Properties Topics MATLAB Command Americas Europe Asia Pacific FAQs References

3-D line plot

collapse all in page

  • 3-D line plot - MATLAB plot3 (1)

Syntax

plot3(X,Y,Z)

plot3(X,Y,Z,LineSpec)

plot3(X1,Y1,Z1,...,Xn,Yn,Zn)

plot3(X1,Y1,Z1,LineSpec1,...,Xn,Yn,Zn,LineSpecn)

plot3(tbl,xvar,yvar,zvar)

plot3(ax,___)

plot3(___,Name,Value)

p = plot3(___)

Description

Vector and Matrix Data

example

plot3(X,Y,Z) plots coordinates in 3-D space.

  • To plot a set of coordinates connected by line segments, specify X, Y, and Z as vectors of the same length.

  • To plot multiple sets of coordinates on the same set of axes, specify at least one of X, Y, or Z as a matrix and the others as vectors.

example

plot3(X,Y,Z,LineSpec) creates the plot using the specified line style, marker, and color.

example

plot3(X1,Y1,Z1,...,Xn,Yn,Zn) plots multiple sets of coordinates on the same set of axes. Use this syntax as an alternative to specifying multiple sets as matrices.

example

plot3(X1,Y1,Z1,LineSpec1,...,Xn,Yn,Zn,LineSpecn) assigns specific line styles, markers, and colors to each XYZ triplet. You can specify LineSpec for some triplets and omit it for others. For example, plot3(X1,Y1,Z1,'o',X2,Y2,Z2) specifies markers for the first triplet but not for the second triplet.

Table Data

example

plot3(tbl,xvar,yvar,zvar) plots the variables xvar, yvar, and zvar from the table tbl. To plot one data set, specify one variable each for xvar, yvar, and zvar. To plot multiple data sets, specify multiple variables for at least one of those arguments. The arguments that specify multiple variables must specify the same number of variables. (since R2022a)

Additional Options

example

plot3(ax,___) displays the plot in the target axes. Specify the axes as the first argument in any of the previous syntaxes.

example

plot3(___,Name,Value) specifies Line properties using one or more name-value pair arguments. Specify the properties after all other input arguments. For a list of properties, see Line Properties.

example

p = plot3(___) returns a Line object or an array of Line objects. Use p to modify properties of the plot after creating it. For a list of properties, see Line Properties.

Examples

collapse all

Plot 3-D Helix

Open Live Script

Define t as a vector of values between 0 and 10π. Define st and ct as vectors of sine and cosine values. Then plot st, ct, and t.

t = 0:pi/50:10*pi;st = sin(t);ct = cos(t);plot3(st,ct,t)

3-D line plot - MATLAB plot3 (2)

Plot Multiple Lines

Open Live Script

Create two sets of x-, y-, and z-coordinates.

t = 0:pi/500:pi;xt1 = sin(t).*cos(10*t);yt1 = sin(t).*sin(10*t);zt1 = cos(t);xt2 = sin(t).*cos(12*t);yt2 = sin(t).*sin(12*t);zt2 = cos(t);

Call the plot3 function, and specify consecutive XYZ triplets.

plot3(xt1,yt1,zt1,xt2,yt2,zt2)

3-D line plot - MATLAB plot3 (3)

Plot Multiple Lines Using Matrices

Open Live Script

Create matrix X containing three rows of x-coordinates. Create matrix Y containing three rows of y-coordinates.

t = 0:pi/500:pi;X(1,:) = sin(t).*cos(10*t);X(2,:) = sin(t).*cos(12*t);X(3,:) = sin(t).*cos(20*t);Y(1,:) = sin(t).*sin(10*t);Y(2,:) = sin(t).*sin(12*t);Y(3,:) = sin(t).*sin(20*t);

Create matrix Z containing the z-coordinates for all three sets.

Z = cos(t);

Plot all three sets of coordinates on the same set of axes.

plot3(X,Y,Z)

3-D line plot - MATLAB plot3 (4)

Specify Equally-Spaced Tick Units and Axis Labels

Open Live Script

Create vectors xt, yt, and zt.

t = 0:pi/500:40*pi;xt = (3 + cos(sqrt(32)*t)).*cos(t);yt = sin(sqrt(32) * t);zt = (3 + cos(sqrt(32)*t)).*sin(t);

Plot the data, and use the axis equal command to space the tick units equally along each axis. Then specify the labels for each axis.

plot3(xt,yt,zt)axis equalxlabel('x(t)')ylabel('y(t)')zlabel('z(t)')

3-D line plot - MATLAB plot3 (5)

Plot Points as Markers Without Lines

Open Live Script

Create vectors t, xt, and yt, and plot the points in those vectors using circular markers.

t = 0:pi/20:10*pi;xt = sin(t);yt = cos(t);plot3(xt,yt,t,'o')

3-D line plot - MATLAB plot3 (6)

Customize Color and Marker

Open Live Script

Create vectors t, xt, and yt, and plot the points in those vectors as a blue line with 10-point circular markers. Use a hexadecimal color code to specify a light blue fill color for the markers.

t = 0:pi/20:10*pi;xt = sin(t);yt = cos(t);plot3(xt,yt,t,'-o','Color','b','MarkerSize',10,... 'MarkerFaceColor','#D9FFFF')

3-D line plot - MATLAB plot3 (7)

Specify Line Style

Open Live Script

Create vector t. Then use t to calculate two sets of x and y values.

t = 0:pi/20:10*pi;xt1 = sin(t);yt1 = cos(t);xt2 = sin(2*t);yt2 = cos(2*t);

Plot the two sets of values. Use the default line for the first set, and specify a dashed line for the second set.

plot3(xt1,yt1,t,xt2,yt2,t,'--')

3-D line plot - MATLAB plot3 (8)

Modify Line After Plotting

Open Live Script

Create vectors t, xt, and yt, and plot the data in those vectors. Return the chart line in the output variable p.

t = linspace(-10,10,1000);xt = exp(-t./10).*sin(5*t);yt = exp(-t./10).*cos(5*t);p = plot3(xt,yt,t);

3-D line plot - MATLAB plot3 (9)

Change the line width to 3.

p.LineWidth = 3;

3-D line plot - MATLAB plot3 (10)

Plot Data from a Table

Open Live Script

Since R2022a

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

Create vectors x, y, and t, and put the vectors in a table. Then display the first three rows of the table.

t = (0:pi/20:10*pi)';x = sin(t);y = cos(t);tbl = table(x,y,t);head(tbl,3)
 x y t _______ _______ _______ 0 1 0 0.15643 0.98769 0.15708 0.30902 0.95106 0.31416

Plot the x, y, and t table variables. Return the Line object as p. Notice that the axis labels match the variable names.

p = plot3(tbl,"x","y","t");

3-D line plot - MATLAB plot3 (11)

To modify aspects of the line, set the LineStyle, Color, and Marker properties on the Line object. For example, change the line to a red dotted line with circular markers.

p.LineStyle = ":";p.Color = "red";p.Marker = "o";

3-D line plot - MATLAB plot3 (12)

Plot Multiple Table Variables on the x- and y-Axes

Open Live Script

Since R2022a

Create a table containing five variables. Then display the first three rows of the table.

t = (0:pi/500:pi)';x1 = sin(t).*cos(10*t);x2 = sin(t).*cos(12*t);y1 = sin(t).*sin(10*t);y2 = sin(t).*sin(12*t);z = cos(t);tbl = table(x1,x2,y1,y2,z);head(tbl,3)
 x1 x2 y1 y2 z _________ _________ __________ __________ _______ 0 0 0 0 1 0.0062707 0.0062653 0.00039452 0.00047329 0.99998 0.012467 0.012423 0.0015749 0.0018877 0.99992

Plot the x1 and x2 variables on the x-axis, the y1 and y2 variables on the y-axis, and the z variable on the z-axis. Then add a legend. Notice that the legend entries match the variable names.

plot3(tbl,["x1","x2"],["y1","y2"],"z")legend

3-D line plot - MATLAB plot3 (13)

Specify Target Axes

Open Live Script

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

tiledlayout(1,2)% Left plotax1 = nexttile;t = 0:pi/20:10*pi;xt1 = sin(t);yt1 = cos(t);plot3(ax1,xt1,yt1,t)title(ax1,'Helix With 5 Turns')% Right plotax2 = nexttile;t = 0:pi/20:10*pi;xt2 = sin(2*t);yt2 = cos(2*t);plot3(ax2,xt2,yt2,t)title(ax2,'Helix With 10 Turns')

3-D line plot - MATLAB plot3 (14)

Plot Duration Data with Custom Tick Format

Open Live Script

Create x and y as vectors of random values between 0 and 1. Create z as a vector of random duration values.

x = rand(1,10);y = rand(1,10);z = duration(rand(10,1),randi(60,10,1),randi(60,10,1));

Plot x, y, and z, and specify the format for the z-axis as minutes and seconds. Then add axis labels, and turn on the grid to make it easier to visualize the points within the plot box.

plot3(x,y,z,'o','DurationTickFormat','mm:ss')xlabel('X')ylabel('Y')zlabel('Duration')grid on

3-D line plot - MATLAB plot3 (15)

Plot Line With Marker at One Data Point

Open Live Script

Create vectors xt, yt, and zt. Plot the values, specifying a solid line with circular markers using the LineSpec argument. Specify the MarkerIndices property to place one marker at the 200th data point.

t = 0:pi/500:pi;xt(1,:) = sin(t).*cos(10*t);yt(1,:) = sin(t).*sin(10*t);zt = cos(t);plot3(xt,yt,zt,'-o','MarkerIndices',200)

3-D line plot - MATLAB plot3 (16)

Input Arguments

collapse all

Xx-coordinates
scalar | vector | matrix

x-coordinates, specified as a scalar, vector, or matrix. The size and shape of X depends on the shape of your data and the type of plot you want to create. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify X, Y, and Z as scalars and include a marker. For example:

plot3(1,2,3,'o')
One set of points

Specify X, Y, and Z as any combination of row or column vectors of the same length. For example:

plot3([1 2 3],[4; 5; 6],[7 8 9])
Multiple sets of points
(using vectors)

Specify consecutive sets of X, Y, and Z vectors. For example:

plot3([1 2 3],[4 5 6],[7 8 9],[1 2 3],[4 5 6],[10 11 12])
Multiple sets of points
(using matrices)

Specify at least one of X, Y, or Z as a matrix, and the others as vectors. Each of X, Y, and Z must have at least one dimension that is same size. For best results, specify all vectors of the same shape and all matrices of the same shape. For example:

plot3([1 2 3],[4 5 6],[7 8 9; 10 11 12])

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

Yy-coordinates
scalar | vector | matrix

y-coordinates, specified as a scalar, vector, or matrix. The size and shape of Y depends on the shape of your data and the type of plot you want to create. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify X, Y, and Z as scalars and include a marker. For example:

plot3(1,2,3,'o')
One set of points

Specify X, Y, and Z as any combination of row or column vectors of the same length. For example:

plot3([1 2 3],[4; 5; 6],[7 8 9])
Multiple sets of points
(using vectors)

Specify consecutive sets of X, Y, and Z vectors. For example:

plot3([1 2 3],[4 5 6],[7 8 9],[1 2 3],[4 5 6],[10 11 12])
Multiple sets of points
(using matrices)

Specify at least one of X, Y, or Z as a matrix, and the others as vectors. Each of X, Y, and Z must have at least one dimension that is same size. For best results, specify all vectors of the same shape and all matrices of the same shape. For example:

plot3([1 2 3],[4 5 6],[7 8 9; 10 11 12])

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

Zz-coordinates
scalar | vector | matrix

z-coordinates, specified as a scalar, vector, or matrix. The size and shape of Z depends on the shape of your data and the type of plot you want to create. This table describes the most common situations.

Type of PlotHow to Specify Coordinates
Single point

Specify X, Y, and Z as scalars and include a marker. For example:

plot3(1,2,3,'o')
One set of points

Specify X, Y, and Z as any combination of row or column vectors of the same length. For example:

plot3([1 2 3],[4; 5; 6],[7 8 9])
Multiple sets of points
(using vectors)

Specify consecutive sets of X, Y, and Z vectors. For example:

plot3([1 2 3],[4 5 6],[7 8 9],[1 2 3],[4 5 6],[10 11 12])
Multiple sets of points
(using matrices)

Specify at least one of X, Y, or Z as a matrix, and the others as vectors. Each of X, Y, and Z must have at least one dimension that is same size. For best results, specify all vectors of the same shape and all matrices of the same shape. For example:

plot3([1 2 3],[4 5 6],[7 8 9; 10 11 12])

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | 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

3-D line plot - MATLAB plot3 (17)

"--"Dashed line

3-D line plot - MATLAB plot3 (18)

":"Dotted line

3-D line plot - MATLAB plot3 (19)

"-."Dash-dotted line

3-D line plot - MATLAB plot3 (20)

MarkerDescriptionResulting Marker
"o"Circle

3-D line plot - MATLAB plot3 (21)

"+"Plus sign

3-D line plot - MATLAB plot3 (22)

"*"Asterisk

3-D line plot - MATLAB plot3 (23)

"."Point

3-D line plot - MATLAB plot3 (24)

"x"Cross

3-D line plot - MATLAB plot3 (25)

"_"Horizontal line

3-D line plot - MATLAB plot3 (26)

"|"Vertical line

3-D line plot - MATLAB plot3 (27)

"square"Square

3-D line plot - MATLAB plot3 (28)

"diamond"Diamond

3-D line plot - MATLAB plot3 (29)

"^"Upward-pointing triangle

3-D line plot - MATLAB plot3 (30)

"v"Downward-pointing triangle

3-D line plot - MATLAB plot3 (31)

">"Right-pointing triangle

3-D line plot - MATLAB plot3 (32)

"<"Left-pointing triangle

3-D line plot - MATLAB plot3 (33)

"pentagram"Pentagram

3-D line plot - MATLAB plot3 (34)

"hexagram"Hexagram

3-D line plot - MATLAB plot3 (35)

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

3-D line plot - MATLAB plot3 (36)

"green""g"[0 1 0]

3-D line plot - MATLAB plot3 (37)

"blue""b"[0 0 1]

3-D line plot - MATLAB plot3 (38)

"cyan" "c"[0 1 1]

3-D line plot - MATLAB plot3 (39)

"magenta""m"[1 0 1]

3-D line plot - MATLAB plot3 (40)

"yellow""y"[1 1 0]

3-D line plot - MATLAB plot3 (41)

"black""k"[0 0 0]

3-D line plot - MATLAB plot3 (42)

"white""w"[1 1 1]

3-D line plot - MATLAB plot3 (43)

tblSource table
table | timetable

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

xvarTable variables containing x-coordinates
character vector | string array | cell array | pattern | numeric scalar or vector | logical vector | vartype()

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

Indexing SchemeExamples

Variable names:

  • A string, character vector, or cell array.

  • A pattern object.

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

  • ["A","B"] or {'A','B'} — Two variables named A and B

  • "Var"+digitsPattern(1) — Variables named "Var" followed by a single digit

Variable index:

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

  • A vector of numbers.

  • 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

  • [2 3] — The second and third variables from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects variables of a specified type.

  • vartype("categorical") — All the variables containing categorical values

The table variables you specify can contain numeric, categorical, datetime, or duration values. If you specify multiple variables for more than one argument, the number of variables must be the same for each of those arguments.

Example: plot3(tbl,["x1","x2"],"y","z") specifies the table variables named x1 and x2 for the x-coordinates.

Example: plot3(tbl,2,"y","z") specifies the second variable for the x-coordinates.

Example: plot3(tbl,vartype("numeric"),"y","z") specifies all numeric variables for the x-coordinates.

yvarTable variables containing y-coordinates
character vector | string array | cell array | pattern | numeric scalar or vector | logical vector | vartype()

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

Indexing SchemeExamples

Variable names:

  • A string, character vector, or cell array.

  • A pattern object.

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

  • ["A","B"] or {'A','B'} — Two variables named A and B

  • "Var"+digitsPattern(1) — Variables named "Var" followed by a single digit

Variable index:

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

  • A vector of numbers.

  • 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

  • [2 3] — The second and third variables from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects variables of a specified type.

  • vartype("categorical") — All the variables containing categorical values

The table variables you specify can contain numeric, categorical, datetime, or duration values. If you specify multiple variables for more than one argument, the number of variables must be the same for each of those arguments.

Example: plot3(tbl,"x",["y1","y2"],"z") specifies the table variables named y1 and y2 for the y-coordinates.

Example: plot3(tbl,"x",2,"z") specifies the second variable for the y-coordinates.

Example: plot3(tbl,"x",vartype("numeric"),"z") specifies all numeric variables for the y-coordinates.

zvarTable variables containing z-coordinates
character vector | string array | cell array | pattern | numeric scalar or vector | logical vector | vartype()

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

Indexing SchemeExamples

Variable names:

  • A string, character vector, or cell array.

  • A pattern object.

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

  • ["A","B"] or {'A','B'} — Two variables named A and B

  • "Var"+digitsPattern(1) — Variables named "Var" followed by a single digit

Variable index:

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

  • A vector of numbers.

  • 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

  • [2 3] — The second and third variables from the table

  • [false false true] — The third variable

Variable type:

  • A vartype subscript that selects variables of a specified type.

  • vartype("categorical") — All the variables containing categorical values

The table variables you specify can contain numeric, categorical, datetime, or duration values. If you specify multiple variables for more than one argument, the number of variables must be the same for each of those arguments.

Example: plot3(tbl,"x","y",["z1","z2"]) specifies the table variables named z1 and z2 for the z-coordinates.

Example: plot3(tbl,"x","y",2) specifies the second variable for the z-coordinates.

Example: plot3(tbl,"x","y",vartype("numeric")) specifies all numeric variables for the z-coordinates.

axTarget axes
Axes object

Target axes, specified as an Axes object. If you do not specify the axes and if the current axes is Cartesian, then plot3 uses 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: plot3([1 2],[3 4],[5 6],'Color','red') specifies a red line for the plot.

Note

The properties listed here are only a subset. For a complete list, see Line Properties.

ColorColor
[0 0.4470 0.7410] (default) | RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ...

Color, specified as an RGB triplet, a hexadecimal color code, a color name, or a short name. The color you specify sets the line color. It also sets the marker edge color when the MarkerEdgeColor property is set to 'auto'.

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"

3-D line plot - MATLAB plot3 (44)

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

3-D line plot - MATLAB plot3 (45)

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

3-D line plot - MATLAB plot3 (46)

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

3-D line plot - MATLAB plot3 (47)

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

3-D line plot - MATLAB plot3 (48)

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

3-D line plot - MATLAB plot3 (49)

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

3-D line plot - MATLAB plot3 (50)

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

3-D line plot - MATLAB plot3 (51)

"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"

3-D line plot - MATLAB plot3 (52)

[0.8500 0.3250 0.0980]"#D95319"

3-D line plot - MATLAB plot3 (53)

[0.9290 0.6940 0.1250]"#EDB120"

3-D line plot - MATLAB plot3 (54)

[0.4940 0.1840 0.5560]"#7E2F8E"

3-D line plot - MATLAB plot3 (55)

[0.4660 0.6740 0.1880]"#77AC30"

3-D line plot - MATLAB plot3 (56)

[0.3010 0.7450 0.9330]"#4DBEEE"

3-D line plot - MATLAB plot3 (57)

[0.6350 0.0780 0.1840]"#A2142F"

3-D line plot - MATLAB plot3 (58)

Tips

  • Use NaN or Inf to create breaks in the lines. For example, this code plots a line with a break between z=2 and z=4.

     plot3([1 2 3 4 5],[1 2 3 4 5],[1 2 NaN 4 5])
  • plot3 uses colors and line styles based on the ColorOrder and LineStyleOrder properties of the axes. plot3 cycles through the colors with the first line style. Then, it cycles through the colors again with each additional line style.

    You can change the colors and the line styles after plotting by setting the ColorOrder or LineStyleOrder properties on the axes. You can also call the colororder function to change the color order for all the axes in the figure. (since R2019b)

Extended Capabilities

Version History

Introduced before R2006a

expand all

Create plots by passing a table to the plot3 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

  • axis | scatter3 | bar3 | tiledlayout | nexttile | grid

Properties

  • Line Properties

Topics

  • Plot Dates and Times
  • Plot Categorical Data
  • 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.

3-D line plot - MATLAB plot3 (61)

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

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

3-D line plot - MATLAB plot3 (2024)

FAQs

What is not enough input arguments in matlab plot3? ›

"Not enough input arguments" is the correct error message because plot3 allows indefinite triplets of x,y,z inputs. Therefore, it thinks "t" is the first dimension of the second triplet, meaning 2 more inputs must follow.

How to plot a 3D model in Matlab? ›

To plot a 3D surface from a data file in MATLAB, you will need to have the data file open in MATLAB. Once you have the data file available, you can use the plot3 command to plot the data. The plot3 command will create a 3D plot of the data. You can also use the surf command to create a 3D surface plot.

How to plot a 3D graph in Matlab using Excel data? ›

Direct link to this answer
  1. T1 = readtable('Epsilon_Prime.xlsx');
  2. T1.Var2 = str2double(T1.Var2);
  3. x = T1{1,2:end};
  4. y = T1{2:end,1};
  5. z = T1{2:end,2:end};
  6. mesh(x, y, z, 'EdgeColor', 'b');
  7. xlabel('Temp (C)')
  8. ylabel('Freq (Hz)')
Jul 17, 2023

How do you plot XYZ coordinates? ›

In the same way that we plot points in two-dimensional coordinate space by moving out along the x-axis to our x value, and then moving parallel to the y-axis until we find our point, in three-dimensional space we'll move along the x-axis, then parallel to the y-axis, then parallel to the z-axis until we arrive at our ...

How to plot a 3D graph? ›

By default, a 3-column matrix is plotted as scattered points. The first column of the matrix represents the x-coordinates, the second column represents the y-coordinates, and the third column represents the z-coordinates. 1. Define a vector-valued function of a single parameter to create a curve in 3D.

What is not enough input arguments? ›

"Not enough arguments" error is simply an indicative of the fact that you are calling some MATLAB/user-defined function with the wrong syntactical signature. You will need to pass correct number of inputs arguments to any function. Look closely at the exact error message you are recieving.

What is too many input arguments? ›

Too many input arguments

This error message means that you are providing more input variables into a function than it is designed to handle.

What does too many arguments mean in MATLAB? ›

1) Passing a function more input arguments than it expected to receive, perhaps by passing a list of inputs rather than a vector of inputs, or have tried to obtain two outputs from a function that only returns one. 2) You have multiple functions with the same name.

Which command is used to plot a 3-D surface in MATLAB? ›

surf( X , Y , Z ) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y .

How to plot 3-D implicit function in MATLAB? ›

fimplicit3( f ) plots the 3-D implicit function defined by f(x,y,z) = 0 over the default interval [-5 5] for x , y , and z . fimplicit3( f , interval ) specifies the plotting interval for x , y , and z . fimplicit3( ax ,___) plots into the axes specified by ax instead of into the current axes.

What is the angle of a 3-D plot in MATLAB? ›

MATLAB automatically selects a viewpoint that is determined by whether the plot is 2-D or 3-D: For 2-D plots, the default is azimuth = 0° and elevation = 90°. For 3-D plots, the default is azimuth = -37.5° and elevation = 30°.

How to plot visualization in MATLAB? ›

Visualize Data with MATLAB
  1. Click Apps > MATLAB Visualizations.
  2. Click New to start your visualization.
  3. Select a template or an example with sample code, which you can run and explore the results.
  4. Click Create.

How to plot a graph in MATLAB using data? ›

Create Simple Line Plots

Create a table containing three variables. Then pass the table as the first argument to the plot function followed by the names of the variables you want to plot. In this case, plot the Input variable on the x-axis and the Output1 variable on the y-axis.

Can Excel do 3D plots? ›

Create a 3-D chart

You can also click the See all charts icon in the lower right of the Charts section. This opens the Chart dialog, where you can pick any chart type. Each category usually show both 2D and 3D. Choose one.

How do you plot a 3-D dot in MATLAB? ›

Use scatter3() to create the 3D scatter plot and scale the colors based on a vector of mean values.
  1. % Create 100x3 matrix of [x,y,z] coordinates.
  2. xyz = randi(1000,100,3);
  3. % Create 100x1 vector of means.
  4. mu = rand(100,1).*5;
  5. % Create 3D scatter plot, colorcode the values based on mu values.
Feb 19, 2020

What is XYZ in 3-D? ›

A three-dimensional structure. The x-axis and y-axis represent the first two dimensions; the z-axis, the third dimension. In a graphic image, the x and y denote width and height; the z denotes depth.

How to create 3-D geometry in MATLAB? ›

Use multicuboid , multicylinder , or multisphere to create a 3-D geometry. Then assign the resulting geometry to the Geometry property of the model. For example, create a PDE model and add the following geometry formed by three spheres to the model. model = createpde; gm = multisphere([1,2,3]); model.

References

Top Articles
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 6636

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.