我试图在matlab中使用颜色条生成散点图,其中最小值的颜色为蓝色,最大值为红色。我可以使用文件交换中的redblue colomap(例如http://www.mathworks.com/matlabcentral/fileexchange/25536-red-blue-colormap)
来完成此操作以下是一个例子:
dd = [70.7 140.0 902.0
70.2 138.6 765.0
68.4 141.2 645.0
67.8 133.2 735.0
64.9 137.7 398.0
63.8 145.1 583.0
74.6 126.6 1880.0
82.8 124.3 -71.0
91.8 124.7 1315.0
93.1 119.6 400.0
95.7 117.0 326.0
104.3 121.3 179.0
104.4 122.0 205.0
104.4 122.3 181.0
104.6 113.0 265.0
109.8 118.2 170.0
55.0 149.6 913.0];
scatter(dd(:,1),dd(:,2),80,dd(:,3),'filled');
box on;
colormap(redblue);
c = colorbar;
我想改变颜色条,使白色区域指零。这可以通过将caxis改为:
来完成caxis([-1800 1800]);
但是在这个例子中这没有意义,因为大多数点都在0以上。因此,我希望找到一种方法,使颜色条从-200到1800,但颜色条中有白色仍然是零。这可能吗?
答案 0 :(得分:2)
这是更新后的代码
dd = [70.7 140.0 902.0
70.2 138.6 765.0
68.4 141.2 645.0
67.8 133.2 735.0
64.9 137.7 398.0
63.8 145.1 583.0
74.6 126.6 1880.0
82.8 124.3 -71.0
91.8 124.7 1315.0
93.1 119.6 400.0
95.7 117.0 326.0
104.3 121.3 179.0
104.4 122.0 205.0
104.4 122.3 181.0
104.6 113.0 265.0
109.8 118.2 170.0
55.0 149.6 913.0];
scatter(dd(:,1),dd(:,2),80,dd(:,3),'filled');
box on;
%% color map begin
m = size(get(gcf,'colormap'),1);
m2 = floor(m*0.9);
r2 = ones(m2,1);
b2 = flipud((0:m2-1)'/max(m2-1,1));
g2 = b2;
m1 = m-m2;
r1 = (0:m2-1)'/max(m2-1,1);
r1(1:(m2-m1))=[];
g1 = r1;
b1 = ones(m1,1);
r = [r1; r2];
g = [g1; g2];
b = [b1; b2];
cm = [r g b];
%% color map end
colormap(cm);
c = colorbar;
caxis([-200 1800]);
如果您不希望colormap
对称。然后使用此
dd = [70.7 140.0 902.0
70.2 138.6 765.0
68.4 141.2 645.0
67.8 133.2 735.0
64.9 137.7 398.0
63.8 145.1 583.0
74.6 126.6 1880.0
82.8 124.3 -71.0
91.8 124.7 1315.0
93.1 119.6 400.0
95.7 117.0 326.0
104.3 121.3 179.0
104.4 122.0 205.0
104.4 122.3 181.0
104.6 113.0 265.0
109.8 118.2 170.0
55.0 149.6 913.0];
scatter(dd(:,1),dd(:,2),80,dd(:,3),'filled');
box on;
%% color map begin
m = size(get(gcf,'colormap'),1);
m2 = floor(m*0.9);
r2 = ones(m2,1);
b2 = flipud((0:m2-1)'/max(m2-1,1));
g2 = b2;
m1 = m-m2;
r1 = (0:m1-1)'/max(m1-1,1);
g1 = r1;
b1 = ones(m1,1);
r = [r1; r2];
g = [g1; g2];
b = [b1; b2];
cm = [r g b];
%% color map end
colormap(cm);
c = colorbar;
caxis([-200 1800]);