scatter
Scatter plot
Syntax
scatter(x,y)
scatter(x,y,sz)
scatter(x,y,sz,c)
scatter(___,'filled')
scatter(___,mkr)
scatter(___,Name,Value)
scatter(ax,___)
s = scatter(___)
描述
scatter(___,
fills in the circles. Use the'filled'
)'filled'
option with any of the input argument combinations in the previous syntaxes.
scatter(___,
modifies the scatter chart using one or more name-value pair arguments. For example,Name,Value
)'LineWidth',2
sets the marker outline width to 2 points.
Examples
Create Scatter Plot
Createx
as 200 equally spaced values between 0 and。Createy
as cosine values with random noise. Then, create a scatter plot.
x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); scatter(x,y)
Vary Circle Size
Create a scatter plot using circles with different sizes. Specify the size in points squared
x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); sz = linspace(1,100,200); scatter(x,y,sz)
Corresponding elements inx
,y
, andsz
determine the location and size of each circle. To plot all circles with the equal area, specifysz
as a numeric scalar.
Vary Circle Color
Create a scatter plot and vary the circle color.
x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); c = linspace(1,10,length(x)); scatter(x,y,[],c)
Corresponding elements inx
,y
, andc
determine the location and color of each circle. Thescatter
function maps the elements inc
to colors in the current colormap.
Fill the Markers
Create a scatter plot and fill in the markers.scatter
fills each marker using the color of the marker edge.
x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); sz = 25; c = linspace(1,10,length(x)); scatter(x,y,sz,c,'filled')
Specify Marker Symbol
Create vectorsx
andy
as sine and cosine values with random noise. Then, create a scatter plot and use diamond markers with an area of 140 points squared.
theta = linspace(0,2*pi,150); x = sin(theta) + 0.75*rand(1,150); y = cos(theta) + 0.75*rand(1,150); sz = 140; scatter(x,y,sz,'d')
Change Marker Color and Line Width
Create vectorsx
andy
as sine and cosine values with random noise. Create a scatter plot and set the marker edge color, marker face color, and line width.
theta = linspace(0,2*pi,300); x = sin(theta) + 0.75*rand(1,300); y = cos(theta) + 0.75*rand(1,300); sz = 40; scatter(x,y,sz,'MarkerEdgeColor',[0 .5 .5],。..'MarkerFaceColor',[0 .7 .7],。..'LineWidth',1.5)
Specify Subplot for Scatter Plot
创建一个figure with two subplots and add a scatter plot to each subplot. Use filled diamond markers for the scatter plot in the lower subplot.
x = linspace(0,3*pi,200); y = cos(x) + rand(1,200); ax1 = subplot(2,1,1); scatter(ax1,x,y) ax2 = subplot(2,1,2); scatter(ax2,x,y,'filled','d')
Modify Scatter Series After Creation
Create a scatter plot and return the scatter series object,s
。
theta = linspace(0,1,500); x = exp(theta).*sin(100*theta); y = exp(theta).*cos(100*theta); s = scatter(x,y);
Uses
to query and set properties of the scatter series after it has been created. Set the line width to0.6
point. Set the marker edge color to blue. Set the marker face color using an RGB triplet color.
Note:Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use theset
function instead, such asset(s,'LineWidth',0.6)
。
s.LineWidth = 0.6; s.MarkerEdgeColor ='b'; s.MarkerFaceColor = [0 0.5 0.5];
Input Arguments
x
—x values
vector
xvalues, specified as a vector.x
andy
must 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
andy
must be vectors of equal length.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|categorical
|datetime
|duration
sz
—Marker area
36(default) |numeric scalar|row or column vector|[]
Marker area in points squared, specified in one of these forms:
Numeric scalar — Plot all markers with equal size.
Row or column vector — Use different sizes for each marker. Corresponding elements in
x
,y
, andsz
determine the location and area of each marker. The length ofsz
must equal the length ofx
andy
。[]
— Use the default area of 36 points squared.
The units for the marker area is points squared.
Example:50
Example:[36 25 25 17 46]
c
—Marker color
[0 0 1]
(default) |RGB triplet|three-column matrix of RGB triplets|vector|'r'
|'g'
|'b'
| ...
Marker color, specified in one of these forms:
RGB triplet or color name — Plot all markers with the same color.
Three column matrix of RGB triplets — Use different colors for each marker. Each row of the matrix specifies an RGB triplet color for the corresponding marker. The number of rows must equal the length of
x
andy
。Vector — Use different colors for each marker and linearly map values in
c
to the colors in the current colormap. The length ofc
must equal the length ofx
andy
。To change the colormap for the axes, use thecolormap
function.If you have three points in the scatter plot and want the colors to be indices into the colormap, specify
c
as a three-element column vector.
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 | 描述 | Equivalent RGB Triplet |
---|---|---|
“红色” 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] |
Example:'k'
Example:[1 2 3 4]
mkr
—Marker type
'o'
(default) |'+'
|'*'
|'.'
|'x'
| ...
Marker type, specified as one of the values listed in this table.
Value | 描述 |
---|---|
'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 |
'filled'
—Option to fill interior of markers
'filled'
Option to fill the interior of the markers, specified as'filled'
。使用这个选项标记有一个脸,for example,'o'
or'square'
。Markers that do not have a face and contain only edges do not draw ('+'
,'*'
,'.'
, and'x'
).
The'filled'
option sets theMarkerFaceColor
property of theScatter
object to'flat'
and theMarkerEdgeColor
property to'none'
, so the marker faces draw, but the edges do not.
ax
—Target axes
Axes
object|PolarAxes
object
Target axes, specified as anAxes
object or aPolarAxes
object. If you do not specify the axes and if the current axes are Cartesian axes, then thescatter
function uses the current axes. To plot into polar axes, specify thePolarAxes
object as the first input argument or use thepolarscatter
function.
Name-Value Pair Arguments
Specify optional comma-separated pairs ofName,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
must appear inside single 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.
TheScatter
object properties listed here are only a subset. For a complete list, seeScatter Properties。
'MarkerEdgeColor'
—Marker outline color
'flat'
(default) |'none'
|RGB triplet|'r'
|'g'
|'b'
| ...
Marker outline color, specified'flat'
, an RGB triplet, or one of the color options listed in the table. The default value of'flat'
uses colors from theCData
property.
For a custom color, specify an RGB triplet. 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 | 描述 | Equivalent RGB Triplet |
---|---|---|
“红色” 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] |
'none' |
No color | Not applicable |
Example:[0.5 0.5 0.5]
Example:'blue'
'MarkerFaceColor'
—Marker fill color
'none'
(default) |'flat'
|'auto'
|RGB triplet|'r'
|'g'
|'b'
| ...
Marker fill color, specified as'flat'
,'auto'
, an RGB triplet, or one of the color options listed in the table.
'flat'
— Use theCData
values to set the color.'auto'
— Use the same color as theColor
property for the axes.
For a custom color, specify an RGB triplet. 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 | 描述 | Equivalent RGB Triplet |
---|---|---|
“红色” 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] |
'none' |
No color | Not applicable |
Example:[0.3 0.2 0.1]
Example:'green'
'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
Output Arguments
s
—Scatter
object
Scatter
object
Scatter
object. Uses
to access and modify properties of the scatter chart after it has been created.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
Usage notes and limitations:
sz
must be scalar or empty[]
。c
must be scalar or an RGB triplet.Categorical inputs are not supported.
With tall arrays, the
scatter
function plots in iterations, progressively adding to the plot as more data is read. During the updates, a progress indicator shows the proportion of data that has been plotted. Zooming and panning is supported during the updating process, before the plot is complete. To stop the update process, press the pause button in the progress indicator.
有关更多信息,seeVisualization of Tall Arrays。
See Also
Functions
Properties
External Websites
Introduced before R2006a
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.
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)