recipes : Plotting : Line and Scatter Plots : How do I make a scatter plot?


How do I make a scatter plot and modify the properties of the points?


You can use the plot or the scatter commands. First I will show examples of obtaining a few different styles using plot, before moving on to scatter.

%Make some random data to plot

plot(X,Y,'ok') %Plot the data using open black circles
plot(X,Y,'ok','MarkerFaceColor','r') %Black circles filled in red
plot(X,Y,'.b') %Blue points
plot(X,Y,'or','MarkerSize',10,'MarkerFaceColor','r') %Larger red circles

Note that by default, the plot command joins up points with a line (try running plot(X,Y)). Similar plots can be made with the scatter command, but this also allows for some extra tricks:

%Make some random data to plot

%Plot the data using open blue circles.
%The third argument defines the symbol size

%Same as above, but with filled points that are 
%coloured sequentially using the jet color map


As you can see, there are various ways you can modify a scatter plot. If you run help plot and help scatter you will see the other options available at the command line when you create the plot. However, there are plenty of modifications you can apply to plots after they have been made.

%Make a plot with some random data and keep the plot handle (H)

%You can see all the stuff you can modify by executing;
         DisplayName: ''
            Annotation: [1x1 hg.Annotation]
                 Color: [1 0 0]
             LineStyle: 'none'
             LineWidth: 0.5000
                Marker: '*'
%  etc

%You can modify these as follows:

%If you aren't sure what values a particular parameter will take,
%you can call set without defining a parameter:
>> set(H,'LineStyle')
[ {-} | -- | : | -. | none ]