White space in map grid.

10 views (last 30 days)
IGOR RIBEIRO on 28 Mar 2016
Commented: Chad Greene on 29 Mar 2016
Hello, I'm making a map with surfm but is getting blanks within map grid. I tried to lower the grade, but white space does not come out.
Thank you for your help.

Accepted Answer

Kelly Kearney
Kelly Kearney on 28 Mar 2016
The mapping toolbox functions clip data that intersect the map frame. With coarsely-resolved data, this can leave some undesired whitespace around the edges. With a rectangular projection such as yours, I've found the best way to get around this issue is to set your map boundaries very carefully to the exact edge of the subset of grid cells you're plotting (or just a tiny bit wider, to avoid rounding errors).
Kelly Kearney
Kelly Kearney on 28 Mar 2016
Here's a longer example that shows the problem with some fake data and your map limits:
opts = {...
'frame','on','FEdgeColor',[0.1500 0.1500 0.1500],'FFaceColor','w',...
'origin',[0 0 0],...
'plinelocation',0.5, ...
'mlabelparallel', 'south'};
lt = linspace(-5, 0, 20);
ln = linspace(-62, -59, 20);
latlim{1} = [-3.5 -2.5];
lonlim{1} = [-61 -59.5];
pad = [-1 1] * 0.001;
latlim{2} = lt(interp1(lt, 1:length(lt), latlim{1}, 'nearest')) + pad; % closest bounds
lonlim{2} = ln(interp1(ln, 1:length(ln), lonlim{1}, 'nearest')) + pad; % closest bounds
[lt, ln] = meshgrid(lt, ln);
z = rand(size(lt));
h = struct;
h.fig = figure('color', 'w');
h.ax(1,1) = subplot(2,2,1);
h.ax(1,2) = subplot(2,2,2);
h.ax(2,1) = subplot(2,2,3);
h.ax(2,2) = subplot(2,2,4);
for ir = 1:2
for ic = 1:2
axesm(opts{:}, 'maplatlim', latlim{ir}, 'maplonlim', lonlim{ir});
[x,y] = mfwdtran(lt, ln);
for ii = 1:2
shading flat;
surfm(lt, ln, z);
title(h.ax(1,1), 'Original map limits, plotted with surf');
title(h.ax(1,2), 'Original map limits, plotted with surfm');
title(h.ax(2,1), 'Adjusted map limits limits, plotted with surf');
title(h.ax(2,2), 'Adjusted map limits limits, plotted with surfm');
And the resulting plot:
The top row of plots uses your map limits, with the data plotted two ways:
  • Left: using surf with projected x/y coordinates
  • Right: using surfm, with lat/lon coordinates.
As you can see, the surfm version cuts off values that the surf one doesn't. Simply projecting the coordinates yourself and plotting in the way I do in the top left is one solution to the problem, and is my preferred way of dealing with this problem, but it can be cumbersome if you're plotting lots of datasets and need to pre-project them all.
Solution 2, shown in the bottom row, is to adjust your map axis limits ( 'MapLatLimit', 'MapLonLimit') values so they're just a bit wider than a set of grid cell edges. This can be a better solution if your map boundaries are more flexible, because you can keep using all the built-in mapping plot functions.

Sign in to comment.

More Answers (1)

Chad Greene
Chad Greene on 28 Mar 2016
The surfm function discards a row and column of data on the edges. Here's a brute-force solution:
% Repeat columns on each side of data:
lat = [lat(:,1) lat lat(:,end)];
lon = [lon(:,1) lon lon(:,end)];
z = [z(:,1) z z(:,end)];
% Repeat rows on top and bottom:
lat = [lat(1,:);lat;lat(end,1)];
lon = [lon(1,:);lon;lon(end,1)];
z = [z(1,:);z;z(end,1)];
Chad Greene
Chad Greene on 29 Mar 2016
Interesting. I'll have to keep that in mind.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!