NaN值从轴色彩图获得第一种颜色,默认情况下对应于最小值(NaN除外).您可以使用
CAXIS功能更改最小值设置轴颜色限制的颜色.要为NaN值指定对比色,您可以为NaN值添加特殊颜色作为第一种颜色(1×3向量).
我举了你的例子并做了一个函数(有一些评论):
function [h hcb] = imagescwithnan(a,cm,nanclr)
% IMAGESC with NaNs assigning a specific color to NaNs
%# find minimum and maximum
amin=min(a(:));
amax=max(a(:));
%# size of colormap
n = size(cm,1);
%# color step
dmap=(amax-amin)/n;
%# standard imagesc
him = imagesc(a);
%# add nan color to colormap
colormap([nanclr; cm]);
%# changing color limits
caxis([amin-dmap amax]);
%# place a colorbar
hcb = colorbar;
%# change Y limit for colorbar to avoid showing NaN color
ylim(hcb,[amin amax])
if nargout > 0
h = him;
end
这里caxis语句将颜色映射的第一种颜色分配给最小值amin,但是分配给amin-dmap.所以第一种颜色专门分配给NaNs.
尝试此功能:
a=peaks;
a(a < 0.5) = nan;
imagescwithnan(a,hot,[0 1 1]) %# [0 1 1] is cyan
如果您在函数中注释ylim语句(可以使用附加参数进行控制),则此NaN颜色将位于色彩映射表上.