필터 지우기
필터 지우기

How label data points using text within a for loop

조회 수: 3 (최근 30일)
Patrick Burke
Patrick Burke 2023년 3월 21일
답변: Eric Delgado 2023년 3월 22일
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