White space in map grid.
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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
2 Comments
Kelly Kearney
on 28 Mar 2016
Here's a longer example that shows the problem with some fake data and your map limits:
opts = {...
'mapprojection','miller',...
'frame','on','FEdgeColor',[0.1500 0.1500 0.1500],'FFaceColor','w',...
'angleunits','degrees',...
'LabelUnits','degrees','MLabelRound',-2,'PLabelRound',-2,...
'fontname','helvetica',...
'fontweight','bold',...
'origin',[0 0 0],...
'grid','on',...
'parallellabel','on',...
'meridianlabel','on',...
'aspect','normal',...
'flinewidth',1,...
'fontsize',10,...
'mlinelocation',0.5,...
'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
axes(h.ax(ir,ic));
axesm(opts{:}, 'maplatlim', latlim{ir}, 'maplonlim', lonlim{ir});
tightmap;
end
end
[x,y] = mfwdtran(lt, ln);
for ii = 1:2
axes(h.ax(ii,1));
surf(x,y,z);
shading flat;
axes(h.ax(ii,2));
surfm(lt, ln, z);
end
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.
More Answers (1)
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)];
surfm(lat,lon,z)
3 Comments
Kelly Kearney
on 28 Mar 2016
While it's true that surfm (and all surf, pcolor, etc) all drop the last row and column of data when using flat or faceted shading, I think that's unrelated to the OP's issue. The problem with mapping toolbox functions is that they often clip data that is on the edge of the map, even if it isn't on the edge of the full data grid. See my reply for more details.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!