Plot geographic data with DMS labels on y-axis

4 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by