How to I have meridian labels switch from E to W across International Date Line?

5 Ansichten (letzte 30 Tage)
I need to make a map that is centered on the date line. I see this changes from W to E across the prime meridian, but not the reverse at the date line. Can someone point out what I need to set to have this work? A brief code is:
latlim = [47 55];
lonlim = [165 -165];
axesm('mercator','MapLatLimit',latlim,'MapLonLimit',lonlim,...
'Frame','on','Grid','on',...
'MeridianLabel','on','ParallelLabel','on',...
'mlabellocation',[165:5:195], ...
'plabellocation',[48:2:56],...
'labelformat','compass',...
'Fontsize',6);
gridm('mlinelocation',5,'plinelocation',2);
If I change mlabellocation to the actual E/W values like below, then all the W ones are missing.
setm(gca,'mlabellocation',[165 170 175 180 -175 -170 -165])

Akzeptierte Antwort

Catherine
Catherine am 29 Aug. 2022
I got a solution from support that works. Here are the details:
Unfortunately, there is not a direct Name-Value pair, property, or function that does this easily, but it is being looked at as a potential future improvement for the "Mapping Toolbox." Instead, we have to implement a bit of a workaround with the labels themselves.
Basically, we will do almost exactly what you had provided, but we will grab all of the labels, modify the degree values, and substitute them back into the map plot. Below is the code that should allow you to do this:
latlim = [47 55]; lonlim = [165 -165];
axesm('mercator','MapLatLimit',latlim,'MapLonLimit',lonlim,...
'Frame','on','Grid','on',...
'ParallelLabel','on',...
'mlabellocation',[165:5:195], ...
'plabellocation',[48:2:56],...
'labelformat','compass',...
'Fontsize',6);
gridm('mlinelocation',5,'plinelocation',2);
h = mlabel('on');
for i=1:length(h) labelString=string(h(i).String{1});
value = str2double(extractBetween(labelString,2,"^"));
value = wrapTo360(value);
if value > 180 value = 360 - value;
labelString = strcat(" ",num2str(value),"^{\circ} W");
h(i).String{1} = labelString;
end
end
They also suggested I include this link as that is almost the reverse of my problem, but might be helpful no matter what your use-case is:

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by