scatter3
3-D scatter plot
Syntax
Description
scatter3(
与指定的颜色吸引每个圆X
,Y
,Z
,S
,C
)C
.
If
C
is a RGB triplet or character vector or string containing a color name, then all circles are plotted with the specified color.If
C
is a three column matrix with the number of rows inC
equal to the length ofX
,Y
, andZ
, then each row ofC
specifies an RGB color value for the corresponding circle.If
C
是一个向量长度等于the length ofX
,Y
, andZ
, then the values inC
are linearly mapped to the colors in the current colormap.
scatter3(___,
fills in the circles, using any of the input argument combinations in the previous syntaxes.'filled'
)
scatter3(___,
specifies the marker type.markertype
)
scatter3(___,
modifies the scatter chart using one or more name-value pair arguments.Name,Value
)
例子
Create 3-D Scatter Plot
Create a 3-D scatter plot. Usesphere
to define vectorsx
,y
, andz
.
figure [X,Y,Z] = sphere(16); x = [0.5*X(:); 0.75*X(:); X(:)]; y = [0.5*Y(:); 0.75*Y(:); Y(:)]; z = [0.5*Z(:); 0.75*Z(:); Z(:)]; scatter3(x,y,z)
Vary Marker Size
Usesphere
to define vectorsx
,y
, andz
.
[X,Y,Z] = sphere(16); x = [0.5*X(:); 0.75*X(:); X(:)]; y = [0.5*Y(:); 0.75*Y(:); Y(:)]; z = [0.5*Z(:); 0.75*Z(:); Z(:)];
Define vectors
to specify the marker sizes.
S = repmat([100,50,5],numel(X),1); s = S(:);
Create a 3-D scatter plot and useview
to change the angle of the axes in the figure.
figure scatter3(x,y,z,s) view(40,35)
Corresponding entries inx
,y
,z
, ands
determine the location and size of each marker.
Vary Marker Color
Usesphere
to define vectorsx
,y
, andz
.
[X,Y,Z] = sphere(16); x = [0.5*X(:); 0.75*X(:); X(:)]; y = [0.5*Y(:); 0.75*Y(:); Y(:)]; z = [0.5*Z(:); 0.75*Z(:); Z(:)];
Define vectorss
andc
to specify the size and color of each marker.
S = repmat([50,25,10],numel(X),1); C = repmat([1,2,3],numel(X),1); s = S(:); c = C(:);
Create a 3-D scatter plot and useview
to change the angle of the axes in the figure.
figure scatter3(x,y,z,s,c) view(40,35)
Corresponding entries inx
,y
,z
, andc
determine the location and color of each marker.
Fill in Markers
创建向量x
andy
as cosine and sine values with random noise.
z = linspace(0,4*pi,250); x = 2*cos(z) + rand(1,250); y = 2*sin(z) + rand(1,250);
Create a 3-D scatter plot and fill in the markers. Useview
to change the angle of the axes in the figure.
scatter3(x,y,z,'filled') view(-30,10)
Set Marker Type
Initialize the random-number generator to make the output ofrand
repeatable. Define vectorsx
andy
as cosine and sine values with random noise.
rngdefaultz = linspace(0,4*pi,250); x = 2*cos(z) + rand(1,250); y = 2*sin(z) + rand(1,250);
Create a 3-D scatter plot and set the marker type. Useview
to change the angle of the axes in the figure.
figure scatter3(x,y,z,'*') view(-30,10)
Set Marker Properties
Initialize the random-number generator to make the output ofrand
repeatable. Define vectorsx
andy
as cosine and sine values with random noise.
rngdefaultz = linspace(0,4*pi,250); x = 2*cos(z) + rand(1,250); y = 2*sin(z) + rand(1,250);
Create a 3-D scatter plot and set the marker edge color and the marker face color. Useview
to change the angle of the axes in the figure.
figure scatter3(x,y,z,...'MarkerEdgeColor','k',...'MarkerFaceColor',[0 .75 .75]) view(-30,10)
Specify Axes for 3-D Scatter Plot
Starting in R2019b, you can display a tiling of plots using thetiledlayout
andnexttile
functions.
Load theseamount
data set to get vectorsx
,y
, andz
. Call thetiledlayout
function to create a 2-by-1 tiled chart layout. Call thenexttile
function to create the axes objectsax1
andax2
. Then create separate scatter plots in the axes by specifying the axes object as the first argument toscatter3
.
loadseamounttiledlayout(2,1) ax1 = nexttile; ax2 = nexttile; scatter3(ax1,x,y,z,'MarkerFaceColor',[0 .75 .75]) scatter3(ax2,x,y,z,'*')
Set Scatter Series Properties Using Handle
Use thesphere
function to create vectorsx
,y
, andz
.
[X,Y,Z] = sphere(16); x = [0.5*X(:); 0.75*X(:); X(:)]; y = [0.5*Y(:); 0.75*Y(:); Y(:)]; z = [0.5*Z(:); 0.75*Z(:); Z(:)];
创建向量s
andc
to specify the size and color for each marker.
S = repmat([70,50,20],numel(X),1); C = repmat([1,2,3],numel(X),1); s = S(:); c = C(:);
Create a 3-D scatter plot and return the scatter series object.
h = scatter3(x,y,z,s,c);
Use an RGB triplet color value to set the marker face color. Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use theset
function instead.
h.MarkerFaceColor = [0 0.5 0.5];
Input Arguments
X
—x values
vector
xvalues, specified as a vector.X
,Y
, andZ
必须be vectors of equal length.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|categorical
|datetime
|duration
Y
—y values
vector
yvalues, specified as a vector.X
,Y
, andZ
必须be vectors of equal length.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|categorical
|datetime
|duration
Z
—z values
vector
zvalues, specified as a vector.X
,Y
, andZ
必须be vectors of equal length.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|categorical
|datetime
|duration
S
—Marker area
36(default) |scalar|vector|[]
Marker area, specified as a scalar, a vector, or[]
. The values inS
必须be positive. The units for area are points squared.
If
S
is a scalar, thenscatter3
plots all markers with the specified area.If
S
is a row or column vector, then each entry inS
specifies the area for the corresponding marker. The length ofS
必须equal the length ofX
,Y
andZ
. Corresponding entries inX
,Y
,Z
andS
determine the location and area of each marker.If
S
is empty, then the default size of 36 points squared is used.
Example:50
Example:[36,25,25,17,46]
C
—Marker color
[0 0 1]
(blue)(default) |RGB triplet|three-column matrix of RGB triplets|vector|'r'
|'g'
|'b'
| ...
Marker color, specified as a an RGB triplet, a three-column matrix of RGB triplet, a vector, or one of the color options in the table.
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]
. Alternatively, you can specify some common colors by name. This table lists the long and short color name options and the equivalent RGB triplet values.
Option | Description | Equivalent RGB Triplet |
---|---|---|
'red' or'r' |
Red | [1 0 0] |
'green' or'g' |
Green | [0 1 0] |
'blue' or'b' |
Blue | [0 0 1] |
'yellow' or'y' |
Yellow | [1 1 0] |
'magenta' or'm' |
Magenta | [1 0 1] |
'cyan' or'c' |
Cyan | (0 1 1) |
'white' or'w' |
White | [1 1 1] |
'black' or'k' |
Black | [0 0 0] |
If you have three points in the scatter plot and want the colors to be indices into the colormap, specifyC
as a three-element column vector.
Example:'y'
Example:[1,2,3,4]
markertype
—Marker
'o'
(default) |'+'
|'*'
|'.'
|'x'
| ...
Marker, specified as one of the markers in this table.
Value | Description |
---|---|
'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 markers |
ax
—Axes object
axes object
Axes object. If you do not specify an axes, thenscatter3
plots into the current axes.
Name-Value Pair Arguments
Specify optional comma-separated pairs ofName,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
必须appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN
.
'MarkerFaceColor','red'
sets the marker face color to red.
The properties listed here are only a subset. For a complete list, seeScatter Properties.
'LineWidth'
—Width of marker edge
0.5
(default) |positive value
Width of marker edge, specified as a positive value in point units.
Example:0.75
'MarkerEdgeColor'
—Marker outline color
'flat'
(default) |RGB triplet|hexadecimal color code|'r'
|'g'
|'b'
| ...
Marker outline color, specified'flat'
, an RGB triplet, a hexadecimal color code, a color name, or a short name. The default value of'flat'
uses colors from theCData
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 from0
toF
. The values are not case sensitive. Thus, 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 Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|---|---|
'red' |
'r' |
[1 0 0] |
'#FF0000' |
|
'green' |
'g' |
[0 1 0] |
'#00FF00' |
|
'blue' |
'b' |
[0 0 1] |
'#0000FF' |
|
'cyan' |
'c' |
(0 1 1) |
'#00FFFF' |
|
'magenta' |
'm' |
[1 0 1] |
'#FF00FF' |
|
'yellow' |
'y' |
[1 1 0] |
'#FFFF00' |
|
'black' |
'k' |
[0 0 0] |
'#000000' |
|
'white' |
'w' |
[1 1 1] |
'#FFFFFF' |
|
'none' |
Not applicable | Not applicable | Not applicable | No color |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB®uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] |
'#0072BD' |
|
[0.8500 0.3250 0.0980] |
'#D95319' |
|
[0.9290 0.6940 0.1250] |
'#EDB120' |
|
[0.4940 0.1840 0.5560] |
'#7E2F8E' |
|
[0.4660 0.6740 0.1880] |
'#77AC30' |
|
[0.3010 0.7450 0.9330] |
'#4DBEEE' |
|
[0.6350 0.0780 0.1840] |
'#A2142F' |
|
Example:[0.5 0.5 0.5]
Example:'blue'
Example:'#D2F9A7'
'MarkerFaceColor'
—Marker fill color
'none'
(default) |'flat'
|'auto'
|RGB triplet|hexadecimal color code|'r'
|'g'
|'b'
| ...
Marker fill color, specified as'flat'
,'auto'
, an RGB triplet, a hexadecimal color code, a color name, or a short name. The'flat'
option uses theCData
values. The'auto'
option uses the same color as theColor
property for the axes.
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 from0
toF
. The values are not case sensitive. Thus, 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 Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|---|---|
'red' |
'r' |
[1 0 0] |
'#FF0000' |
|
'green' |
'g' |
[0 1 0] |
'#00FF00' |
|
'blue' |
'b' |
[0 0 1] |
'#0000FF' |
|
'cyan' |
'c' |
(0 1 1) |
'#00FFFF' |
|
'magenta' |
'm' |
[1 0 1] |
'#FF00FF' |
|
'yellow' |
'y' |
[1 1 0] |
'#FFFF00' |
|
'black' |
'k' |
[0 0 0] |
'#000000' |
|
'white' |
'w' |
[1 1 1] |
'#FFFFFF' |
|
'none' |
Not applicable | Not applicable | Not applicable | No color |
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.
RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|
[0 0.4470 0.7410] |
'#0072BD' |
|
[0.8500 0.3250 0.0980] |
'#D95319' |
|
[0.9290 0.6940 0.1250] |
'#EDB120' |
|
[0.4940 0.1840 0.5560] |
'#7E2F8E' |
|
[0.4660 0.6740 0.1880] |
'#77AC30' |
|
[0.3010 0.7450 0.9330] |
'#4DBEEE' |
|
[0.6350 0.0780 0.1840] |
'#A2142F' |
|
Example:[0.3 0.2 0.1]
Example:'green'
Example:'#D2F9A7'
Output Arguments
h
—Scatter
object
Scatter
object
Scatter
object. This is a unique identifier, which you can use to query and modify the properties of theScatter
object after it is created.
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
This function accepts GPU arrays, but does not run on a GPU.
For more information, seeRun MATLAB Functions on a GPU(Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
Usage notes and limitations:
This function operates on distributed arrays, but executes in the client MATLAB.
For more information, seeRun MATLAB Functions with Distributed Arrays(Parallel Computing Toolbox).
See Also
Functions
Properties
Introduced before R2006a
Open Example
A modified version of this example exists on your system. Do you want to open this version instead?
MATLAB命令
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.
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:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
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
- United Kingdom(English)