Plot geographic data with DMS labels on y-axis

5 visualizaciones (últimos 30 días)
bene1
bene1 el 29 de En. de 2022
Comentada: bene1 el 1 de Feb. de 2022
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.

Respuesta aceptada

Voss
Voss el 29 de En. de 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.

Más respuestas (0)

Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by