Plot geographic data with DMS labels on y-axis
6 views (last 30 days)
Show older comments
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.

0 Comments
Accepted Answer
Voss
on 29 Jan 2022
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.
More Answers (0)
See Also
Categories
Find more on Geographic Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!