散点图的颜色从暗到亮

Pla*_*god 0 matlab scatter colors matlab-figure

我想散布一些不同颜色的数据。第一行应该是深蓝色,每一行应该变得更亮一些。目前,我只完成了从深蓝色到其他颜色到黄色的制作。

这是我的代码:

c = linspace(1,10,length(x));
sz = 25;
scatter(x,y, sz,c,'filled');
colorbar
Run Code Online (Sandbox Code Playgroud)

随着结果的情节。

在此处输入图片说明

如何使颜色从深蓝色渐变为浅蓝色?

Adr*_*aan 5

您的点从蓝色变为黄色的原因是因为它们使用默认的颜色映射:parula。有各种可用的颜色图,但没有用于蓝色的内置颜色图。但是,您可以使用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
Run Code Online (Sandbox Code Playgroud)

黑蓝

RGB三元组是三个元素的行向量:[red green blue],其中[0 0 0]黑色和[1 1 1]白色。离开前两个元素为零,并从使所述第三运行01将导致从黑色标纯蓝色。

另外,如果您要从黑色变成纯蓝色,再变成纯白色,则可以像以前一样先饱和蓝色,然后将其保留不变,然后在下半部分同时逐渐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
Run Code Online (Sandbox Code Playgroud)

黑蓝白