【问题标题】:Make NaN white with mapshow MatLab使用 mapshow MatLab 将 NaN 设为白色
【发布时间】:2021-05-26 00:52:15
【问题描述】:

我在 MatLab 中使用 mapshow,但我有一些没有数据的多边形,我想将其留空(即白色)。现在它显示默认的黄色。我能做什么?

链接到带有 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 的数据矩阵,那么您可以使用 isnan() 函数获得指示所有 NaN 位置的二进制掩码。然后,您应该能够在这些位置分配您想要的颜色。
  • 谢谢,请找到上面的新代码,它几乎可以在任何最新版本的 MatLab 中运行。 NaN 显示为黄色区域,如何使它们保持白色,以保持其他区域的颜色图的其余部分?

标签: matlab colors mapping nan


【解决方案1】:

我自己找到了解决方案。将“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)

【讨论】:

    猜你喜欢
    • 2015-10-24
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2018-05-16
    • 2018-10-01
    • 1970-01-01
    相关资源
    最近更新 更多