我想散布一些颜色不同的数据。第一行应该是深蓝色,每一行应该变得更亮一些。目前,我只完成了从深蓝色到其他颜色到黄色的制作。
这是我的代码:
c = linspace(1,10,length(x));
sz = 25;
scatter(x,y, sz,c,'filled');
colorbar
包含结果图。
如何使颜色从深蓝色渐变为浅蓝色?
答案 0 :(得分:5)
您的点从蓝色变为黄色的原因是因为它们使用默认的颜色映射:parula。有various colour maps available,但没有内置的蓝色配色图。但是,您可以使用RGB三重奏轻松定义它:
n = 30; % The higher the number, the more points and the more gradual the scale
x = rand(n,1);
y = rand(n,1);
c = linspace(0,1,length(x)).'; % Range from 0 to 1
RGB = zeros(length(x),3); % Red is zero, green is zero, blue builds up
RGB(:,3) = c;
sz = 25;
scatter(x,y, sz,RGB,'filled');
colormap(RGB) % Sets the correct colours for the colour bar
colorbar
RGB三元组是包含三个元素的行向量:[red green blue]
,其中[0 0 0]
是黑色,[1 1 1]
是白色。将前两个元素保留为零,并使第三个元素从0
到1
,将导致颜色范围从黑色变为纯蓝色。
或者,如果您要从黑色变成纯蓝色再变成纯白色,则可以像以前一样先将蓝色饱和,然后将其保留在1
处,然后将红色和绿色逐渐增加到1
同时在下半年:
n = 30;
x = rand(n,1);
y = rand(n,1);
c = linspace(0,1,floor(length(x))./2).'; % Go to 1 in half the length
RGB = zeros(length(x),3);
RGB(1:floor(length(x)/2),3) = c; % Sets the blue
RGB(floor(length(x)/2)+1:end,1) = c; % Sets the red
RGB(floor(length(x)/2)+1:end,2) = c; % Sets the green
RGB(floor(length(x)/2)+1:end,3) = 1; % Leaves blue at 1
sz = 25;
h1 = scatter(x,y, sz,RGB,'filled');
colormap(RGB);
colorbar