# 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

<span style="color: #0000ff;">scatter</span>

and

<span style="color: #0000ff;">plot</span>

.

# Scatter

<span style="color: #0000ff;">scatter(</span>t,v<span style="color: #0000ff;">)</span>

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

<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>200<span style="color: #0000ff;">)</span>

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

scattersizes=100*<span style="color: #ff0000;">[</span>1<span style="color: #ff00ff;">;</span>2<span style="color: #ff00ff;">;</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #ff00ff;">;</span>5<span style="color: #ff00ff;">;</span>6<span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #0000ff;">)</span>

## Fill

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

scattersizes=100*<span style="color: #ff0000;">[</span>1<span style="color: #ff00ff;">;</span>2<span style="color: #ff00ff;">;</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #ff00ff;">;</span>5<span style="color: #ff00ff;">;</span>6<span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span>

## MarkerEdgeColor and MarkerFaceColor

scattersizes=100*<span style="color: #ff0000;">[</span>1<span style="color: #ff00ff;">;</span>2<span style="color: #ff00ff;">;</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #ff00ff;">;</span>5<span style="color: #ff00ff;">;</span>6<span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeColor</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>[<span style="color: #ff0000;">192/255</span><span style="color: #808080;">,</span><span style="color: #339966;">0/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">0/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceColor</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span>[<span style="color: #ff0000;">112/255</span><span style="color: #808080;">,</span><span style="color: #339966;">48/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">160/255</span>]<span style="color: #0000ff;">)</span>

## LineWidth

scattersizes=100*<span style="color: #ff0000;">[</span>1<span style="color: #ff00ff;">;</span>2<span style="color: #ff00ff;">;</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #ff00ff;">;</span>5<span style="color: #ff00ff;">;</span>6<span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeColor</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>[<span style="color: #ff0000;">192/255</span><span style="color: #808080;">,</span><span style="color: #339966;">0/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">0/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceColor</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span>[<span style="color: #ff0000;">112/255</span><span style="color: #808080;">,</span><span style="color: #339966;">48/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">160/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">LineWidth</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>3)

## MarkerEdgeAlpha and MarkerFaceColor

scattersizes=100*<span style="color: #ff0000;">[</span>1<span style="color: #ff00ff;">;</span>2<span style="color: #ff00ff;">;</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #ff00ff;">;</span>5<span style="color: #ff00ff;">;</span>6<span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeColor</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>[<span style="color: #ff0000;">192/255</span><span style="color: #808080;">,</span><span style="color: #339966;">0/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">0/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceColor</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span>[<span style="color: #ff0000;">112/255</span><span style="color: #808080;">,</span><span style="color: #339966;">48/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">160/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">LineWidth</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>3<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceAlpha</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>0.5<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeAlpha</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>0.5)

# Axes, Grid and Legend

The functions for axes and legends are identical for a figure made using

<span style="color: #0000ff;">scatter</span>

and

<span style="color: #0000ff;">plot</span>

I will only go through it briefly here, for more details see plot .

# Hold

<span style="color: #0000ff;">hold</span>

is also identical for a figure made using

<span style="color: #0000ff;">scatter</span>

and

<span style="color: #0000ff;">plot</span>

once again, I will only go through it briefly here, for more details see plot .

scattersizes=100*<span style="color: #ff0000;">[</span>1<span style="color: #ff00ff;">;</span>2<span style="color: #ff00ff;">;</span>3<span style="color: #ff00ff;">;</span>4<span style="color: #ff00ff;">;</span>5<span style="color: #ff00ff;">;</span>6<span style="color: #ff0000;">]</span><span style="color: #ff00ff;">;</span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,</span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeColor</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>[<span style="color: #ff0000;">59/255</span><span style="color: #808080;">,</span><span style="color: #339966;">145/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">207/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceColor</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span>[<span style="color: #ff0000;">116/255</span><span style="color: #808080;">,</span><span style="color: #339966;">116/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">116/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">LineWidth</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>3<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceAlpha</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>0.5<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeAlpha</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>0.5)
<span style="color: #000000;"><span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">on</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span></span>
<span style="color: #0000ff;">scatter(</span>t<span style="color: #808080;">,<span style="color: #000000;">2*</span></span>v<span style="color: #808080;">,</span>scattersizes<span style="color: #808080;">,</span><span style="color: #800080;">'</span><span style="color: #ff9900;">fill</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeColor</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>[<span style="color: #ff0000;">192/255</span><span style="color: #808080;">,</span><span style="color: #339966;">0/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">0/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceColor</span><span style="color: #800080;">'<span style="color: #808080;">,</span></span>[<span style="color: #ff0000;">112/255</span><span style="color: #808080;">,</span><span style="color: #339966;">48/255</span><span style="color: #808080;">,</span><span style="color: #0000ff;">160/255</span>]<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">LineWidth</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>3<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerFaceAlpha</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>0.5<span style="color: #808080;">,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">MarkerEdgeAlpha</span><span style="color: #800080;">'</span><span style="color: #808080;">,</span>0.5)
<span style="color: #000000;"><span style="color: #0000ff;">hold(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">off</span><span style="color: #800080;">'</span><span style="color: #0000ff;">)</span></span>
<span style="color: #0000ff;">set(</span>gca,<span style="color: #ff00ff;">...</span><span style="color: #0000ff;"><span style="color: #800080;">
'<span style="color: #ff9900;">FontSize</span>'<span style="color: #000000;">,20</span></span>)</span>
<span style="color: #3366ff;">xlabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">time (s)</span><span style="color: #800080;">'</span><span style="color: #3366ff;">)</span>
<span style="color: #3366ff;">ylabel(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">speed (m/s)</span><span style="color: #800080;">'</span><span style="color: #3366ff;">)</span>
<span style="color: #3366ff;">title(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">Rocket Projectile</span><span style="color: #800080;">'</span><span style="color: #3366ff;">)</span>
<span style="color: #3366ff;">grid(<span style="color: #ffcc00;"><span style="color: #800080;">'</span><span style="color: #ff9900;">minor</span><span style="color: #800080;">'</span></span>)</span>

<span style="color: #3366ff;">legend(</span><span style="color: #800080;">'</span><span style="color: #ff9900;">Rocket1</span><span style="color: #800080;">'</span><span style="color: #000000;">,<span style="color: #800080;">'</span><span style="color: #ff9900;">Rocket2</span><span style="color: #800080;">'</span>,</span><span style="color: #ff00ff;">...</span>
<span style="color: #800080;">'</span><span style="color: #ff9900;">Location</span><span style="color: #800080;">'</span>,<span style="color: #800080;">'</span><span style="color: #ff9900;">NorthWest</span><span style="color: #800080;">'</span><span style="color: #3366ff;">)</span>

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