scatter
Scatter plot.
Syntax
- scatter(x, y)
- scatter(x, y, sz)
- scatter(x, y, sz, c)
- scatter(..., 'filled')
- scatter(..., marker)
- scatter(ax, ...)
- scatter(..., propertyName, propertyValue)
- s = scatter(...)
Input argument
- X - x-coordinates: vector or matrix.
- Y - y-coordinates: vector or matrix.
- sz - Marker size: numeric scalar, vector, [] (default: 36)
- c - Marker color: color name, RGB triplet or vector of colormap indices
- ax - a scalar graphics object value: parent container, specified as a axes.
- propertyName - a scalar string or row vector character. see help of 'line' for property list.
- propertyValue - a value.
Output argument
- s - a graphics object: line type or group of line.
Description
scatter(x, y) generates a scatter plot by placing circular markers at the coordinates defined by the vectors x and y.
If you intend to display a single dataset, ensure that both x and y are vectors of the same length.
To visualize multiple datasets on a shared set of axes, you can achieve this by using a matrix for either x or y, while keeping the other as a vector.
This allows you to overlay or compare multiple datasets within the same plot.
marker specifies the symbol to be drawn at each data point:
'o': Circle symbol
'x': Times symbol
'+': Plus symbol
'*': Asterisk symbol
'.': Dot symbol
's': Square symbol
'd': Diamond symbol
'v': Downward-pointing triangle symbol
'^': Upward-pointing triangle symbol
'>': Left-pointing triangle symbol
'<': Right-pointing triangle symbol
The ColorSpec specifies the marker color to use for each data series:
'k': Color Black
'y': Color Yellow
'm': Color Magenta
'c': Color Cyan
'r': Color Red
'b': Color Blue
'g': Color Green
see line for more information about properties
Examples
f = figure();
theta = linspace(0,1,600);
x = exp(theta).*sin(110*theta);
y = exp(theta).*cos(110*theta);
s = scatter(x,y ,'filled');
f = figure();
x = linspace(0,3*pi,255);
y = cos(x) + rand(1,255);
sz = 1:255;
c = 1:length(x);
scatter(x, y, sz, c, 'd', 'filled')
f = figure();
x = linspace(0, 3*pi, 255);
y = cos(x) + rand(1, 255);
c = linspace(1,10,length(x));
scatter(x, y, [], c, 'filled')
f = figure();
theta = linspace(0,2*pi,244);
x = sin(theta) + 0.75*rand(1,244);
y = cos(theta) + 0.75*rand(1,244);
sz = 45;
scatter(x,y,sz,'MarkerEdgeColor',[0 .6 .5], 'MarkerFaceColor',[0 .6 .7], 'LineWidth',3.5)
f = figure(),
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
% Top plot
ax1 = subplot(2,1, 1);
scatter(ax1,x,y)
% Bottom plot
ax2 = subplot(2,1, 2);
scatter(ax2,x,y,'filled','d')
f = figure();
x = rand(500,5);
y = randn(500,5) + (5:5:25);
s = scatter(x,y, 'filled');
See also
History
Version | Description |
---|---|
1.0.0 | initial version |
Author
Allan CORNET