Plot geographic data with DMS labels on y-axis

I have geographic data that treats latitude and longitude separately. I am plotting the points' latitudes and error bars against their index number. I would like the y-axis to display DMS ticks (degrees, minutes, seconds), like 40° 0' 28.2".
I'm currently plotting with the data in degrees, though I also have it available in DMS.
errorbar(idx, deg, sigmaDeg, '.', 'Color', 'k', 'MarkerSize',15)
yline(degMean,'red', 'LineWidth', 1)
From what I can tell, geoscatter is useful for DMS data, but this data has geographic values in only one dimension. Is there a way to get my y-axis into DMS, either by altering the axis properties or manipulating my data?
Thank you.

 채택된 답변

Voss
Voss 2022년 1월 29일
Something like this would work:
errorbar(1:7, 40.00785+0.00001*randn(1,7), 0.00001*randn(1,7), '.', 'Color', 'k', 'MarkerSize',15)
% yline(degMean,'red', 'LineWidth', 1)
yt = get(gca(),'YTick');
yd = floor(yt);
yt = (yt-yd)*60;
ym = floor(yt);
ys = (yt-ym)*60;
ytl = arrayfun(@(d,m,s)sprintf('%d° %d'' %.2f''''',d,m,s),yd,ym,ys,'UniformOutput',false);
set(gca(),'YTickLabel',ytl);
You can put those few lines of code after any code you have that generates a plot that you want to label with DMS labels.
If you want the labels to update when you zoom/pan on the plot, you could put those commands in a function, with minor modification, and do this:
set(zoom,'ActionPostCallback',@set_DMS_yticklabels);
set(pan,'ActionPostCallback',@set_DMS_yticklabels);
function set_DMS_yticklabels(~,evt)
yt = get(evt.Axes,'YTick');
yd = floor(yt);
yt = (yt-yd)*60;
ym = floor(yt);
ys = (yt-ym)*60;
ytl = arrayfun(@(d,m,s)sprintf('%d° %d'' %.2f''''',d,m,s),yd,ym,ys,'UniformOutput',false);
set(evt.Axes,'YTickLabel',ytl);
end
That would probably work ok.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Geographic Plots에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2022년 1월 29일

댓글:

2022년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by