Plot geographic data with DMS labels on y-axis
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Geographic Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
