Varying Marker Color by Variable with plotm

조회 수: 12 (최근 30일)
Cari
Cari 2025년 2월 6일
댓글: Cari 2025년 2월 6일
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]);

채택된 답변

Walter Roberson
Walter Roberson 2025년 2월 6일
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
Walter Roberson
Walter Roberson 2025년 2월 6일
marker_size = 20;
marker_color = table.low_range;
scatterm(table.latitude, table.longitude, marker_size, marker_color);
Cari
Cari 2025년 2월 6일

Ah, I see. Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Wireless Communications에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by