从渐变蓝色到白色的轮廓线颜色图

时间:2020-09-26 16:09:10

标签: matlab colormap contourf

我想将绘图中的颜色图从黄色更改为蓝色,从蓝色更改为白色;只有两种颜色带有渐变。有可能吗?

代码:

x = randn(1000,1);
y = randn(1000,1);
[N,Xedges,Yedges] = histcounts2(x,y);
contourf(N)

任何帮助都非常欢迎。

1 个答案:

答案 0 :(得分:2)

您可以使用colormap功能指定要在图中使用的颜色图。色图只是一个三列矩阵,其值介于01之间,代表R,G,B分量,因此您可以手动创建它。例如,要生成一个从蓝色到白色的简单色图:

N = 256; % number of colors
cmap = [linspace(1,0,N).' linspace(1,0,N).' ones(N,1)]; % decreasing R and G; B = 1
colormap(cmap)

enter image description here

但是,此色图在感知上并不均匀,也就是说,在整个颜色范围内,感知到的“色差”不是均匀的。要生成从蓝色到白色的感知均匀的颜色图,我建议用户使用'Blues'选项提供的BrewerMap函数:

N = 256; % number of colors
cmap = brewermap(N, 'Blues');
colormap(cmap)

enter image description here