Next: 2.1.3.6 Function plots
Up: 2.1.3 Other 2-D plots
Previous: 2.1.3.4 Parametric plots
  Contents
Scatter plots allow us to change the size, shape, or color of each data
point. We can use this feature to let the size or color of the plotted
points represent an additional variable.
For example, let's select 10 random spots in the
-
plane and place a
random charge at each point. The magnitude of the charge will vary from
to
pC. We'll represent the position of the charge by it's place
on the plot. The magnitude of the charge will be represented by the size of
the point, and the sign of the charge will be indicated by color,
blue for
and red for
. Here is how to do it.
clear all % clear memory
clc; % clear command window
close all; % close any figure windows that are open
N = 10; % Number of charges to place
xq=rand(1,N); % x positions of the charges
yq=rand(1,N); % y positions of the charges
q=100*rand(1,N)-50; % magnitude of charges (between -50 and 50)
color = 1.5+sign(q)/2; % sign(q) returns 1 or -1, so color is 1 or 2
size = abs(q)*100; % Make size of points bigger for bigger magnitude of q
scatter(xq,yq,size,color,'filled')
axis square
This example uses some MATLAB you haven't seen
yet: rand for generating random numbers between 0 and 1, sign
for getting the sign of number, and the scatter plot command. Look
up each of these in MATLAB's help.
Next: 2.1.3.6 Function plots
Up: 2.1.3 Other 2-D plots
Previous: 2.1.3.4 Parametric plots
  Contents
Gus Hart
2005-01-28