Scatter Plots in MATLAB

This guide continues on from my guide on the plot function which discusses some of the perquisites required for the scatter function such as selecting the columns of data you wish to plot from a variable or table and discusses the Colours and Marker Styles in more detail. The functions for axes and legends are also identical for a figure made using scatter and plot.

Scatter

scatter(t,v)

Marker Size

The scatter function also has an additional argument which corresponds to the MarkerSize. If a scalar is used, all Markers are the same size:

scatter(t,v,200)

Alternatively a Vector may be used to individually specify the size of each point.

scattersizes=100*[1;2;3;4;5;6];
scatter(t,v,scattersizes)

Fill

The additional string of characters argument 'fill' can be used to fill in the Markers

scattersizes=100*[1;2;3;4;5;6];
scatter(t,v,scattersizes,'fill')

MarkerEdgeColor and MarkerFaceColor

scattersizes=100*[1;2;3;4;5;6];
scatter(t,v,scattersizes,'fill',...

'MarkerEdgeColor',[192/255,0/255,0/255],...
'MarkerFaceColor',[112/255,48/255,160/255])

LineWidth

scattersizes=100*[1;2;3;4;5;6];
scatter(t,v,scattersizes,'fill',...

'MarkerEdgeColor',[192/255,0/255,0/255],...
'MarkerFaceColor',[112/255,48/255,160/255],...
'LineWidth',3)

MarkerEdgeAlpha and MarkerFaceColor

scattersizes=100*[1;2;3;4;5;6];
scatter(t,v,scattersizes,'fill',...
'MarkerEdgeColor',[192/255,0/255,0/255],...
'MarkerFaceColor',[112/255,48/255,160/255],...
'LineWidth',3,...

'MarkerFaceAlpha',0.5,...
'MarkerEdgeAlpha',0.5)

Axes, Grid and Legend

The functions for axes and legends are identical for a figure made using scatter and plot I will only go through it briefly here, for more details see plot .


Hold

hold is also identical for a figure made using scatter and plot once again, I will only go through it briefly here, for more details see plot .

scattersizes=100*[1;2;3;4;5;6];
scatter(t,v,scattersizes,'fill',...
'MarkerEdgeColor',[59/255,145/255,207/255],...
'MarkerFaceColor',[116/255,116/255,116/255],...
'LineWidth',3,...

'MarkerFaceAlpha',0.5,...
'MarkerEdgeAlpha',0.5)

hold('on')
scatter(t,2*v,scattersizes,'fill',...
'MarkerEdgeColor',[192/255,0/255,0/255],...
'MarkerFaceColor',[112/255,48/255,160/255],...
'LineWidth',3,...

'MarkerFaceAlpha',0.5,...
'MarkerEdgeAlpha',0.5)
hold('off')

set(gca,...
'FontSize',20
)

xlabel('time (s)')
ylabel('speed (m/s)')
title('Rocket Projectile')

grid('minor')

legend('Rocket1','Rocket2',...
'Location','NorthWest')

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.