# Scatter in MATLAB®

How to make a scatter plot in MATLAB®. Seven examples of the scatter function.

### Simple Scatter Plot

load seamount x y z;

fig = figure;
scatter(x, y, 10, z);

title('Undersea Elevation');
xlabel('Longitude');
ylabel('Latitude');

fig2plotly();


### Scatter Plot from Array values ( Discrete Points )

x = [1 2 3 4 5]
y = [3 4 6 3 6]
% Create a scatter plot using the scatter function

fig = figure;
scatter(x, y);

% Add title and axis labels
title('Simple Plot from array');
xlabel('X');
ylabel('Y');

fig2plotly(fig);


### Scatter Plot with Colors and Sizes

fig = figure;
s = 10;
c = linspace(1,10,length(x));
scatter(x,y,s,c)
zoom(2)

fig2plotly(fig, 'strip', false);


### Plotting Specific Array Column

a=[1:10;sin(1:10);cos(1:10)]';

fig = figure
scatter(a(:,1), a(:,2));
title('Sample Data');

fig2plotly(fig);

### Plotting Complex Data (Real and Imaginary Parts)

x = -2:0.25:2;
z1 = x.^exp(-x.^2);
z2 = 2*x.^exp(-x.^2);
real_z1 = real(z1);
imag_z1 = imag(z1);

real_z2 = real(z2);
imag_z2 = imag(z2);

plot(real_z1,imag_z1,'g*',real_z2,imag_z2,'bo');
title('Plotting Complex Data');

fig2plotly();

### Specifying Color List using Hold On

X = [linspace(0,100,100); linspace(0,100,100); linspace(0,100,100)]
Y = [randi(100,1,100); randi(100,1,100); randi(100,1,100)]

colors = ['r' 'g' 'b']
fig = figure;
hold on
for i=1:3
disp(colors(i));
scatter(X(i, :), Y(i, :),colors(i));
end;
hold off

fig2plotly(fig, 'strip',false)

### Specifying Different Color for Different Points

X = [1 2 3 4 5]
Y = [5 5 5 5 5]

fig = figure;
colors = ['r' 'g' 'b' 'y' 'c']

hold on;
for i=1:5
scatter(X(i), Y(i), 'LineWidth',10,'MarkerFaceColor',colors(i))
end
hold off;
resp = fig2plotly(fig)