# 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: short color name, 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: scatter type or array of scatter.

## 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.

Scatter Properties:

Scatter Properties:

AlphaData: Marker face transparency, 1 (default) or array the same size as XData

BeingDeleted: Flag indicating that the object is being deleted.

BusyAction: Callback queuing specified as 'queue' (default) or 'cancel'. The property determines how Nelson handles the execution of interrupting callbacks.

CData Marker colors: \[] (default), RGB triplet, matrix of RGB triplets or vector.

marker color to use for each data series:

'k', 'black': Color Black

'y', 'yellow': Color Yellow

'm', 'magenta': Color Magenta

'c', 'cyan': Color Cyan

'r', 'red': Color Red

'b', 'blue': Color Blue

'g', 'green': Color Green

CDataMode Selection mode for CData: 'manual', 'auto' (default).

Children: Children.

CreateFcn: Component creation function.

DeleteFcn: Component deletion function.

DisplayName Legend label: character vector or string scalar, '' (default).

Interruptible: Callback interruption 'on' (default).

LineWidth Line width: scalar positive value.

MarkerMarker symbol:

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

MarkerEdgeColor Marker outline color: RGB triplet.

MarkerEdgeAlpha Marker edge transparency: scalar in range \[0,1], 'flat or 1 (default).

To assign distinct transparency values to the edges of each point in a plot, set the AlphaData property to a vector matching the size of the XData property and set the MarkerEdgeAlpha property to 'flat'.

MarkerFaceColor Marker fill color: RGB triplet.

MarkerFaceAlpha Marker face transparency: scalar in range \[0,1], 'flat or 1 (default).

To assign distinct transparency values to the faces of each point in a plot, set the AlphaData property to a vector matching the size of the XData property and set the MarkerFaceAlpha property to 'flat'.

Parent Parent container: Figure graphics object.

SizeData: Marker sizes:\[] (default), scalar or vector.

Tag Object identifier: character vector, string scalar or '' (default).

Type: Type of graphics object 'scatter'.

UserData User data: array or \[]

Visible State of visibility: 'on' (default) or 'off'.

XData: x values: vector or matrix or \[] (default).

YData: y values: vector or matrix or \[] (default).

ZData: z values: vector or matrix or \[] (default).

XDataMode Selection mode for XData: 'manual' or 'auto'.

## Examples

```matlab
f = figure();
theta = linspace(0,1,600);
x = exp(theta).*sin(110*theta);
y = exp(theta).*cos(110*theta);
s = scatter(x,y ,'filled');
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-ed8d1ef9a171ff1bc6e1d141bdde92fef54c294c%2Fscatter_1_CAF48F8D.svg?alt=media)

```matlab
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')
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-30d9dbd06c25c80b7413b6abea4fa8366865eb6a%2Fscatter_2_220DC9DC.svg?alt=media)

```matlab
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')
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-32d5ada23a3f308babf891b9685f959354d1bd1a%2Fscatter_3_D671E61.svg?alt=media)

```matlab
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)
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-c6dfe5142d47bbbb65522a78c86955419c11a913%2Fscatter_4_7C886888.svg?alt=media)

```matlab
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')
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-71bda3c65001ce1cede4f5c55743a9864cb5dea4%2Fscatter_5_E289BA04.svg?alt=media)

```matlab
f = figure();
x = rand(500,5);
y = randn(500,5) + (5:5:25);
s = scatter(x,y, 'filled');
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-6913a485f550b48fb5e14361b006453ab40b2ea2%2Fscatter_6_1E831925.svg?alt=media)

```matlab
f = figure();
% Create figure
hold on;
% Settings
nPoints = 10; % Number of points per marker type
markers = {'o', '+', '*', 's', 'd', '^', 'v', '>', '<', 'p', 'h'};
sizesMin = 20; % Minimum size
sizesMax = 100; % Maximum size
% X positions
x = linspace(1, 10, nPoints);
% Fixed color
fixedColor = [0 0 0]; % black
% Plot each marker type
for m = 1:numel(markers)
    y = m * ones(size(x)); % Constant Y for each marker type
    sizes = linspace(sizesMin, sizesMax, nPoints); % Increasing sizes
    % Scatter points
    scatter(x, y, sizes, ...
        'Marker', markers{m}, ...
        'MarkerEdgeColor', fixedColor, ...
        'MarkerFaceColor', 'none', ...
        'LineWidth', 1.5);
end
title('Scatter Only - One Line per Marker Type with Increasing Size');
xlabel('X Axis');
ylabel('Marker Type Line');
ylim([0 numel(markers)+1]);
hold off;
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-0662fe586e1a9488a7f3844ed3cbebe8202d1d3b%2Fscatter_7_2AE5E706.svg?alt=media)

## See also

[line](line), [plot](plot), [scatter3](scatter3).

## History

| Version | Description                                   |
| ------- | --------------------------------------------- |
| 1.0.0   | initial version                               |
| 1.12.0  | color name and short color name managed.      |
| 1.14.0  | Scatter is a graphics object with Properties. |

## Author

Allan CORNET
