Как построить трехмерный график в матлабе
Перейти к содержимому

Как построить трехмерный график в матлабе

  • автор:

Как построить трехмерный график в матлабе

Построение трехмерных графиков в Matlab . Перед построением графика функции двух переменных необходимо разбить область построения прямоугольной сеткой с помощью функции meshrid и вычислить значения функции в узлах сетки. После этого можно построить график поверхности с помощью функции mesh ( X , Y , Z ) или surf ( X , Y , Z ). Для подписей осей координат можно воспользоваться функциями xlabel ( text ), ylabel ( text ), zlabel ( text ).

Построение трехмерного графика рассмотрим на примере функции z ( x , y )= y ^2- x ^2 на интервале x Î [-2,2], y Î [-2,2]. Наберем:

3D Plots in Matlab

By Priya PedamkarPriya Pedamkar

3D Plots in Matlab

What is Matlab 3D Plots?

MATLAB is a language used for technical computing. As most of us will agree, an easy to use environment is a must for integrating tasks of computing, visualizing and finally programming. MATLAB does the same by providing an environment that is not only easy to use but also, the solutions that we get are displayed in terms of mathematical notations which most of us are familiar with.

Python TutorialMachine LearningAWSArtificial Intelligence

TableauR ProgrammingPowerBIDeep Learning

Uses of MATLAB for Computing

MATLAB is used in many different ways, following are the list where it is commonly used.

Hadoop, Data Science, Statistics & others

  • Computation
  • Development of Algorithms
  • Modeling
  • Simulation
  • Prototyping
  • Data analytics (Analysis and Visualization of data)
  • Engineering & Scientific graphics
  • Application development

MATLAB provides its user with a basket of functions and tools, in this article we will understand About 3-dimensional plots in MATLAB.

  • Plots are created for data visualization.
  • Data visualization is very powerful in getting the look and feel of the data in just one glance.
  • Data plots have a number of uses from comparing sets of data to tracking data changes over time.

Plots can be created using graphic functions or interactively using the MATLAB Desktop.

Types of 3D Plots in MATLAB

Below we have discussed the types of 3D plots in MATLAB used in computing.

1. PLOT3 (Line Plots)

Plot3 helps in creating 3D lines or Point Plots.

Plot3(x,y,z): If x,y,z are vectors of the same length, then this function will create a set of coordinates connected by line segments. If we specify at least one of x, y or z as vectors, it will plot multiple sets of coordinates for the same set of axes.

Code:

A= 0: pi/100; 50*pi;
sa= sin(a);
ca=cos(a);
plot3(sa, ca, a)

Output:

3D Plots in Matlab 1

plot3(X, Y, Z, LineSpec): This function will create the plot using the specified line style, marker, and color.

A= 0:pi/20:2*pi;
sa= sin(a);
ca=cos(a) ;
plot3(sa, ca, a, ’o’)

Output:

3D Plots in Matlab 2

plot3(X1, Y1, Z1,…, Xn, Yn, Zn): This function will plot multiple coordinates for the same set of axes.

a= 0:pi/100*pi;
xa1= sin(a).cos(10*a);
ya1=sin(a).*sin(10*a) ;
za1=cos(a);
xa2= sin(a).cos(15*a);
ya2=sin(a).*sin(15*a) ;
za2=cos(a);
Plot3(xa1,ya1,za1,xa2,ya2,za2)

Output:

3D Plots in Matlab 3

2. SCATTER3 (3D scatter Plot)

scatter3(X, Y, Z): This function will create circles at the vector locations of x, y, and z.

Example:

X, y, z are vector spheres.

Output:

3D Plots in Matlab 4

scatter3(X, Y, Z, A, C): This function will create a plot with a circle that will have size A from the argument. If A is scalar, the size of the circles will be equal. For the specific size of the circle, we will have to define A as a vector.

Code:

Define a vector to specify the marker sizes.

a = repmat([50,10,2],numel(X),1);
C = repmat([1,2,3],numel(X),1);
a = a(:);
c = c(:);

Output:

3D Plots in Matlab 5

3. CONTOUR3 (3D contour plots)

contour3(Z): Z is a matrix and this function will create a 3-D contour plot which will have the isolines of matrix z will have the height details of x and y plane. The x & y coordinates in the plane are column and row indices of Z. Contour lines are selected by MATLAB automatically.

Code:

[X,Y] = meshgrid(-1:0.20:2);
Z = X.^2 + Y.^2;
contour3(Z)

Output:

3d plot 6

Define contour levels as 30, and display the results within x and y limits.

Code:

Output:

3d plot7

4. QUIVER3 (Velocity Plot)

3D quiver plot creates vectors with components (u,v,w) at the points (x,y,z), where u, v, w, x, y, and z are real values.

x = -3:0.5:3;
y = -3:0.5:3;
[X,Y] = meshgrid(x, y);
Z = Y.^2 — X.^2;
[U,V,W] = surfnorm(Z);

Output:

3d plot8

5. FILL3 (3D filled polygon plot)

This function helps in creating flat shaped and Gouraud polygons (to get different shades of light).

fill3(X, Y, Z, C): It helps in creating filled polygons with vertices x, y, z. The x, y, z values can be number, duration, and DateTime, etc.

Code:

X = [1 2 3 4; 1 1 3 2; 0 1 2 1];
Y = [2 2 1 1; 1 2 1 2; 1 1 0 0];
Z = [1 1 1 1; 1 0 1 0; 0 0 0 0];
C = [0.5000 1.0000 1.0000 0.5000;
1.0000 0.5000 0.5000 0.1667;
0.3330 0.3330 0.5000 0.5000];

Output:

3d plot9

In the above figure, we can clearly see the Gouraud effect.

Conclusion – 3D Plots in Matlab

Data visualization becomes a very powerful technique when we have to understand how our data is behaving. It also tells us visually, how a particular function is changing when it is supplied with different values. 3 D plot in MATLAB is a tool which is very helpful in visualizing the behavior of data.

Recommended Articles

This is a guide to 3D Plots in Matlab. Here we discuss what is Matlab, uses Matlab and types of 3D plot in Matlab for computing. You can also go through our other related articles to learn more –

MATLAB TUTORIAL, part 2: 3D Plotting

matlab provides many useful instructions for the visualization of 3D data. The instructions provided include tools to plot wire-frame objects, 3D plots, curves, surfaces, etc. and can automatically generate contours, display volumetric data, interpolate shading colors and even display non-Matlab made images.

Order Function
plot3(x,y,z,’line shape’) Space curve
meshgrid(x,y) Mesh plot
mesh(x,y,z) hollow mesh surface
surf(x,y,z) mesh surface, solid filled
shading flat flat/smooth surface space
countour3(x,y,z,n) 3-dimensional equivipotential (n) lines
contour(x,y,z) contours
meshc(x,y,z) hollow grid graph projected by equivipotential lines
[x,y,z]=cylinder(r,n) 3-dimensional curve surfaces

We show how to use plotting commands by examples.

Example: Example 0.1.1:

Example: Example 0.1.2:

When using »meshgrid,» the coding should be changed into:

Or the solid filled:

And with the flat surface:

Example: 3-dimensional rotating surface

Example: Consider a 3-dimensional rotating surface ([x,y,z]=cylinder(r,n))
We plot the 3D graph for \( r(t)=2+\sin (t) . \) Using “mesh, cylinder” the code will be as follows

with the Solid filled

Or with the “shading flat”:

Now we plot the function of r(t)=2+sin(t), using the 3-dimension equipotential lines

Example:

a=5; % a and c are arbitrary constants
c=10;
[u,v]=meshgrid(0:10:360); % meshgrid produces a full grid represented by the output coordinate arrays u and v; u and v are time variables
x=(c+a*cosd(v)).*cosd(u); % x, y, and z are the parameterized equations for a toroid
y=(c+a*cosd(v)).*sind(u);
z=a*sind(v);
surfl(x,y,z) % surfl creates a surface plot with colormap-based lighting
axis equal; % scales the axis so the x, y, and z axis are equal

Example 0.1.4: Helix

t = 0:pi/50:10*pi; %create the vector t. starting value of 0, each element increases pi/50 from the previous up through 10*pi
plot3(sin(t),cos(t),t) %3D plot, coordinate (x, y, t)
title(‘Helix’) %creates plot title
xlabel(‘sin(t)’) %creates x label
ylabel(‘cos(t)’) %creates y label
zlabel(‘t’) %creates t label
grid on %dashed grids

Example 0.1.5:

% The Viviani’s Curve is the intersection of sphere x^2 + y^2 + z^2 = 4*a^2
%and cylinder (x-a)^2 +y^2 =a^2
%This script uses parametric equations for the Viviani’s Curve,
%and the cylinder and sphere whose intersection forms the curve.

plot3

  • 3-D line plot

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.

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

plot3( X 1, Y 1, Z 1. X n, Y n, Z n) plots multiple sets of coordinates on the same set of axes. Use this syntax as an alternative to specifying multiple sets as matrices.

plot3( X 1, Y 1, Z 1, LineSpec 1. X n, Y n, Z n, LineSpec n) 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

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

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

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 .

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

Plot 3-D Helix

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 .

Figure contains an axes object. The axes object contains an object of type line.

Plot Multiple Lines

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

Call the plot3 function, and specify consecutive XYZ triplets.

Figure contains an axes object. The axes object contains 2 objects of type line.

Plot Multiple Lines Using Matrices

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

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

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

Figure contains an axes object. The axes object contains 3 objects of type line.

Specify Equally-Spaced Tick Units and Axis Labels

Create vectors xt , yt , and zt .

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.

Figure contains an axes object. The axes object contains an object of type line.

Plot Points as Markers Without Lines

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

Figure contains an axes object. The axes object contains an object of type line.

Customize Color and Marker

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.

Figure contains an axes object. The axes object contains an object of type line.

Specify Line Style

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

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

Figure contains an axes object. The axes object contains 2 objects of type line.

Modify Line After Plotting

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

Figure contains an axes object. The axes object contains an object of type line.

Change the line width to 3 .

Figure contains an axes object. The axes object contains an object of type line.

Plot Data from a Table

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.

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

Figure contains an axes object. The axes object contains an object of type line.

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.

Figure contains an axes object. The axes object contains an object of type line.

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

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

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.

Figure contains an axes object. The axes object contains 2 objects of type line.

Specify Target Axes

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 plot 3.

Figure contains 2 axes objects. Axes object 1 with title Helix With 5 Turns contains an object of type line. Axes object 2 with title Helix With 10 Turns contains an object of type line.

Plot Duration Data with Custom Tick Format

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

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.

Figure contains an axes object. The axes object contains an object of type line.

Plot Line With Marker at One Data Point

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.

Figure contains an axes object. The axes object contains an object of type line.

Input Arguments

X — x-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.

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

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

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

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:

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

Y — y-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.

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

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

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

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:

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

Z — z-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.

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

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

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

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:

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

LineSpec — Line style, marker, and color
string | character vector

Line style, marker, and color, specified as a string 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

Sample of solid line

Sample of dashed line

Sample of dotted line

Sample of dash-dotted line, with alternating dashes and dots

Sample of circle marker

Sample of plus sign marker

Sample of asterisk marker

Sample of point marker

Sample of cross marker

Sample of horizontal line marker

Sample of vertical line marker

Sample of square marker

Sample of diamond line marker

Sample of upward-pointing triangle marker

Sample of downward-pointing triangle marker

Sample of right-pointing triangle marker

Sample of left-pointing triangle marker

Sample of pentagram marker

Sample of hexagram marker

Sample of the color red

Sample of the color green

Sample of the color blue

Sample of the color cyan

Sample of the color magenta

Sample of the color yellow

Sample of the color black

Sample of the color white

tbl — Source table
table | timetable

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

xvar — Table 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.

A string, character vector, or cell array.

«A» or ‘A’ — A variable called A

[«A»,»B»] or <'A','B'>— Two variables called A and B

«Var»+digitsPattern(1) — Variables named «Var» followed by a single digit

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

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.

yvar — Table 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.

A string, character vector, or cell array.

«A» or ‘A’ — A variable called A

[«A»,»B»] or <'A','B'>— Two variables called A and B

«Var»+digitsPattern(1) — Variables named «Var» followed by a single digit

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

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.

zvar — Table 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.

A string, character vector, or cell array.

«A» or ‘A’ — A variable called A

[«A»,»B»] or <'A','B'>— Two variables called A and B

«Var»+digitsPattern(1) — Variables named «Var» followed by a single digit

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

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.

ax — Target 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 .

Color — Color
[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 character vector or a string scalar 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.

Sample of the color red

Sample of the color green

Sample of the color blue

Sample of the color cyan

Sample of the color magenta

Sample of the color yellow

Sample of the color black

Sample of the color white

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

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

LineWidth — Line width
0.5 (default) | positive value

Line width, specified as a positive value in points, where 1 point = 1/72 of an inch. If the line has markers, then the line width also affects the marker edges.

The line width cannot be thinner than the width of a pixel. If you set the line width to a value that is less than the width of a pixel on your system, the line displays as one pixel wide.

MarkerSize — Marker size
6 (default) | positive value

Marker size, specified as a positive value in points, where 1 point = 1/72 of an inch.

MarkerEdgeColor — Marker outline color
«auto» (default) | RGB triplet | hexadecimal color code | «r» | «g» | «b» | .

Marker outline color, specified as «auto» , an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of «auto» uses the same color as the Color property.

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 character vector or a string scalar 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.

Sample of the color red

Sample of the color green

Sample of the color blue

Sample of the color cyan

Sample of the color magenta

Sample of the color yellow

Sample of the color black

Sample of the color white

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

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

Sample of RGB triplet [0.8500 0.3250 0.0980], which appears as dark orange

Sample of RGB triplet [0.9290 0.6940 0.1250], which appears as dark yellow

Sample of RGB triplet [0.4940 0.1840 0.5560], which appears as dark purple

Sample of RGB triplet [0.4660 0.6740 0.1880], which appears as medium green

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

MarkerFaceColor — Marker fill color
«none» (default) | «auto» | RGB triplet | hexadecimal color code | «r» | «g» | «b» | .

Marker fill color, specified as «auto» , an RGB triplet, a hexadecimal color code, a color name, or a short name. The «auto» option uses the same color as the Color property of the parent axes. If you specify «auto» and the axes plot box is invisible, the marker fill color is the color of the figure.

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 character vector or a string scalar 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.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *