MATLAB: How to hide the grid lines behind a marker in map axes using GRIDM function in Mapping Toolbox 3.2 (R2010b)

gridgridmhidemapmarkerMATLABvisibility

When I use GRIDM for a map containing a marker, the grid lines appear in front of the marker.
axesm('pcarree','MapLatLimit',[-90 90],'MapLonLimit',[-90 90]);
gridm
plotm(0,0,'o','markersize',18,'markerfacecolor','g');
I want to hide the grid lines behind the marker.

Best Answer

The grid lines appear in front of the marker as the default ‘ZData’ property of grid lines is positive. Set the ‘ZData’ values of grid lines to be negative.
axesm('pcarree','MapLatLimit',[-90 90],'MapLonLimit',[-90 90]);
Hg = gridm;
plotm(0,0,'o','markersize',18,'markerfacecolor','g');
% Get the size of 'Zdata'
Z1n=size(get(Hg(1),'ZData'));
Z2n=size(get(Hg(2),'ZData'));
% set the ‘ZData’ values to -1
set(Hg(1),'ZData',-ones(Z1n));
set(Hg(2),'ZData',-ones(Z2n));
Related Question