使用 mapshow MatLab 使 NaN 变白
Make NaN white with mapshow MatLab
我在 MatLab 中使用 mapshow,但我有一些没有数据的多边形,我想将其留空(即颜色为白色)。现在它显示默认的黄色。我能做什么?
link 与 NaN 映射:https://i.stack.imgur.com/fyr82.png
下面的可重现代码,
MapLatLimit = [41 48];
MapLonLimit = [-74 -66];
NEstates = shaperead('usastatelo', 'UseGeoCoords', true, 'BoundingBox', [MapLonLimit' MapLatLimit']);
fall = flipud(bone(numel(NEstates)));
datawithNaN = num2cell([10 20 30 NaN 40 50 NaN NaN]);
[NEstates.datawithNaN] = deal(datawithNaN{:});
densityColors = makesymbolspec('Polygon', {'datawithNaN', [0 50], 'FaceColor', fall});
mapshow(NEstates, 'DisplayType', 'polygon', 'SymbolSpec', densityColors)
我自己找到了解决方案。将 'NaN' 本身视为一个类别,然后为其分配颜色。下面的代码。
MapLatLimit = [41 48];
MapLonLimit = [-74 -66];
NEstates = shaperead('usastatelo', 'UseGeoCoords', true, 'BoundingBox', [MapLonLimit' MapLatLimit']);
datawithNaN = [30 20 30 NaN 40 50 NaN NaN];
% Here replace NaNs with a number (treat as category):
datawithNaN(isnan(datawithNaN)) = 0;
datawithNaN = num2cell(datawithNaN);
% Here I create a color map, using white for NaN (category = 0);
mycolormap = [ 1 1 1;...
.4 .1 .9;...
.3 .2 .8;...
.2 .3 .7;...
.1 .4 .6];
[NEstates.datawithNaN] = deal(datawithNaN{:});
densityColors = makesymbolspec('Polygon', {'datawithNaN', [0 50], 'FaceColor', mycolormap});
mapshow(NEstates, 'DisplayType', 'polygon', 'SymbolSpec', densityColors)
我在 MatLab 中使用 mapshow,但我有一些没有数据的多边形,我想将其留空(即颜色为白色)。现在它显示默认的黄色。我能做什么?
link 与 NaN 映射:https://i.stack.imgur.com/fyr82.png
下面的可重现代码,
MapLatLimit = [41 48];
MapLonLimit = [-74 -66];
NEstates = shaperead('usastatelo', 'UseGeoCoords', true, 'BoundingBox', [MapLonLimit' MapLatLimit']);
fall = flipud(bone(numel(NEstates)));
datawithNaN = num2cell([10 20 30 NaN 40 50 NaN NaN]);
[NEstates.datawithNaN] = deal(datawithNaN{:});
densityColors = makesymbolspec('Polygon', {'datawithNaN', [0 50], 'FaceColor', fall});
mapshow(NEstates, 'DisplayType', 'polygon', 'SymbolSpec', densityColors)
我自己找到了解决方案。将 'NaN' 本身视为一个类别,然后为其分配颜色。下面的代码。
MapLatLimit = [41 48];
MapLonLimit = [-74 -66];
NEstates = shaperead('usastatelo', 'UseGeoCoords', true, 'BoundingBox', [MapLonLimit' MapLatLimit']);
datawithNaN = [30 20 30 NaN 40 50 NaN NaN];
% Here replace NaNs with a number (treat as category):
datawithNaN(isnan(datawithNaN)) = 0;
datawithNaN = num2cell(datawithNaN);
% Here I create a color map, using white for NaN (category = 0);
mycolormap = [ 1 1 1;...
.4 .1 .9;...
.3 .2 .8;...
.2 .3 .7;...
.1 .4 .6];
[NEstates.datawithNaN] = deal(datawithNaN{:});
densityColors = makesymbolspec('Polygon', {'datawithNaN', [0 50], 'FaceColor', mycolormap});
mapshow(NEstates, 'DisplayType', 'polygon', 'SymbolSpec', densityColors)