MATLAB Answers

Moving map labels towards/away from axis

7 views (last 30 days)
Jakob Weis
Jakob Weis on 29 Jul 2020
Commented: dpb on 29 Jul 2020
Hi,
I am trying to move the meridian/parallel labels in a map created with the mapping toolbox, i.e. increase the space between the labels and the map.
After a day of looking for an easy solution this is what I came up with:
%% MWE
figure(4);clf
axMap = worldmap([-60 -30],[160 190]);
setm(axMap,'mapprojection','eqdcylin')
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(axMap, land, 'FaceColor', [0.8 0.8 0.8])
setm(axMap,'FontSize', 20)
set(findobj(axMap.Children, 'Tag', 'MLabel'),'Units','points') % convert label position from 'data' to 'points'
mlabels = findobj(axMap.Children, 'Tag', 'MLabel'); % find all labels
labelpos = get(findobj(axMap.Children, 'Tag', 'MLabel'),'Position'); % get the positions of each label
for iL = 1 : length(labelpos) % loop over each label
labelpos{iL}(2) = labelpos{iL}(2) + 15; % add desired offset to the label position
set(mlabels(iL),'Position',labelpos{iL}) % set new label position
end
It works but seems like a horribly cumbersome approach to something that should be achievable in an easier way. I have looked through the map axis properties but couldn't find anything allowing me to change the label position relative to the axis. Note: mlabelparallel and plabelmeridian are not what I'm looking for.
Am I missing something?
Thank you!
  1 Comment
dpb
dpb on 29 Jul 2020
" I have looked through the map axis properties but couldn't find anything allowing me to change the label position relative to the axis. ...Am I missing something?"
I don't have the toolbox to be able to test, but perhaps.
Try
saxMap=struct(axMap)
which will reveal all properties of the map axis object including those that are normally hidden. Oftentimes one can find the pieces of the object looking for that TMW didn't think were important for the end user.
Good luck "handle-diving"! :)

Sign in to comment.

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!