How label data points using text within a for loop

5 次查看(过去 30 天)
I am trying to produce a map of tide gauges using Geoscatter and then label each tide gauge with its corresponding tide gauge number. I have an array, A, that contains 58 tide guages - each one with it's own tide gauge number. I also have arrays for longitude and latitude that corresponds to each tide gauge number. So far, I have got this:
load('A.mat');
load('PSMSL+ERA5IB.mat');
geoscatter(Latitude(A),Longitude(A),20)
for i=1:58
text(Longitude(A(i)),Latitude(A(i)),string(A(i)));
end
This produces a map, but doesn't give the labels for the tide gauges. I'm not sure why

回答(1 个)

Eric Delgado
Eric Delgado 2023-3-22
It seems that you have to create a custom data tips...
rawData = table([-13;-30], [-39; -39], ["ID 1"; "ID 2"], 'VariableNames', {'lat', 'long', 'label'})
rawData = 2×3 table
lat long label ___ ____ ______ -13 -39 "ID 1" -30 -39 "ID 2"
figure
h = geoscatter(rawData.lat, rawData.long);
h.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Label', rawData.label);
datatip(h, -13, -39);
datatip(h, -30, -39);

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by