How label data points using text within a for loop

4 Ansichten (letzte 30 Tage)
Patrick Burke
Patrick Burke am 21 Mär. 2023
Beantwortet: Eric Delgado am 22 Mär. 2023
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

Antworten (1)

Eric Delgado
Eric Delgado am 22 Mär. 2023
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);

Kategorien

Mehr zu Graphics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by