MATLAB: Marker size based on value

colordotmarkermarkersizeplotscatterscattermsize;

I am wanting to recreate the following plot but with the size of the dots changing based on the magnitude (mag) value.
Here is my code so far:
data = load(filename) ;
long = data(:,1) ;
lati = data(:,2) ;
year = data(:,3) ;
mag = data(:,6) ;
for i = 1:length(mag)
if mag(i) < 3.0
mag(i) = NaN ;
lati(i) = NaN ;
long(i) = NaN ;
end
end
new_lati = zeros(length(lati),1) ;
new_long = zeros(length(long),1) ;
new_lati1 = zeros(length(lati),1) ;
new_long1 = zeros(length(long),1) ;
for i = 1:length(lati)
if new_lati(i) == 0
new_lati(i) = NaN ;
end
if new_long(i) == 0
new_long(i) = NaN ;
end
if new_lati1(i) == 0
new_lati1(i) = NaN ;
end
if new_long1(i) == 0
new_long1(i) = NaN ;
end
if year(i) > 2008
new_lati(i) = lati(i) ;
new_long(i) = long(i) ;
end
if year(i) > 2013
new_lati1(i) = lati(i) ;
new_long1(i) = long(i) ;
end
end
latlim = [33 39];
lonlim = [-102 -94];
figure
ax = usamap(latlim,lonlim) ;
set(ax, 'Visible', 'off')
states = shaperead('usastatehi',...
'UseGeoCoords', true, 'BoundingBox', [lonlim', latlim']);
geoshow(ax, states, 'FaceColor', [1.0 0.9 0.7])
lat = [states.LabelLat];
lon = [states.LabelLon];
tf = ingeoquad(lat, lon, latlim, lonlim);
hold on
h1 = linem(lati, long, 'LineStyle','none', 'LineWidth',2, 'Color','b', ...
'Marker','.', 'MarkerSize',10) ;
h2 = linem(new_lati, new_long, 'LineStyle','none', 'LineWidth',2, 'Color','[0.0 0.8 0.3]', ...
'Marker','.', 'MarkerSize',10) ;
h3 = linem(new_lati1, new_long1, 'LineStyle','none', 'LineWidth',2, 'Color','r', ...
'Marker','.', 'MarkerSize',10) ;
I have tried using scatterm instead of linem, however didnt know how to keep the corresponding colours.
Any help would be appreciated. Thanks
Gareth

Best Answer

The help for scatterm says:
scatterm(LAT,LON,S,C) displays colored circles at the locations
specified by the vectors LAT and LON (which must be the same size).
So the 3rd argument is your size data and the 4th argument is your color data.
You'll probably need to scale your size data. It wants values which are in "points squared". A point is 1/72 of an inch. So if I want my largest markers to be 1 inch across, I would do something like this:
seamount = load('seamount.mat');
lat = seamount.y;
lon = seamount.x;
zrange = [min(seamount.z), max(seamount.z)];
cdata = seamount.z;
size_data = (cdata-zrange(1)+1) * 72^2 / diff(zrange);
worldmap([-49 -47.5],[-150 -147.5])
scatterm(lat, lon, size_data, cdata,'filled')
Related Question