Varying Marker Color by Variable with plotm

15 visualizaciones (últimos 30 días)
Cari
Cari el 6 de Feb. de 2025
Comentada: Cari el 6 de Feb. de 2025
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]);

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Feb. de 2025
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 comentarios
Walter Roberson
Walter Roberson el 6 de Feb. de 2025
marker_size = 20;
marker_color = table.low_range;
scatterm(table.latitude, table.longitude, marker_size, marker_color);
Cari
Cari el 6 de Feb. de 2025

Ah, I see. Thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Wireless Communications en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by