Varying Marker Color by Variable with plotm

Hello - please forgive my lack of experience with coding, but I am having trouble with some mapping I am trying to do. I am able to plot the locations of a series of samples the data for which comes from a spreadsheet (icee.xlsx) that I have MATLAB read. I would like the marker face colors to correspond to the value of a column of the spreadsheet, (in my code, this would be table.low_range). Currently, I am plotting all of the markers with the same color (line 22 of the below).
Can you please tell me how to change the code below in order to fit a colorbar to the table.low_range variable and vary the face colors of the markers according to it? I have attached a sample of the spreadsheet in question should that help.
clear all
table = readtable('icee.xlsx');
figure;
clf;
%center on the south pole
gisplat=-90;
gisplon=180;
xl=[-.45 .45];
yl=[-.35 .35];
tx=xl(1)+.95*diff(xl);
ty=yl(1)+.06*diff(yl);
ts=14;
mw=.005;
awx=(1-5*mw)/4;
awy=(1-2*mw);
axesm('mapprojection','eqdazim','origin',[gisplat gisplon 0]);
g1=geoshow('landareas.shp');
set(get(g1,'children'),'facecolor',[.9 .9 .9]);
set(gca,'xlim',xl);
set(gca,'ylim',yl);
hold on;
plotm(table.latitude,table.longitude,'ko','markerfacecolor',[.7 .7 1]);
set(gca,'box','off','xcolor',[1 1 1],'ycolor',[1 1 1]);
hg=gridm('on');
set(hg,'clipping','on');
set(hg,'linestyle','-','color',[.75 .75 .75]);

 Accepted Answer

You should probably be using scatterm instead of plotm .
You are using 'ko' line specification, so you are not joining points together... which is perfect for scatterm()
scatterm() permits you to pass colors as an N x 3 RGB table, where N is the number of points, thus providing direct RGB per-point.
scatterm() also permits you to pass a vector of N values, where N is the number of points. In this case, the vector is mapped through CLim processes and interpolated to get a color table index.

3 Comments

My apologies for my inexperience, but I think the latter portion of your answer may be beyond me at the moment. Would I just replace the plotm function (is that the right word?) with scatterm? To vary the marker-face colors then, would I define an array as table.low_range, then use colorbar?

marker_size = 20;
marker_color = table.low_range;
scatterm(table.latitude, table.longitude, marker_size, marker_color);

Ah, I see. Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021b

Asked:

on 6 Feb 2025

Commented:

on 6 Feb 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!