颜色由暗到亮的散点图

Scatter plot with colors from dark to bright

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

这是我的代码:

c = linspace(1,10,length(x));
sz = 25;
scatter(x,y, sz,c,'filled');
colorbar

有了结果图。

如何制作从深蓝到浅蓝的渐变色阶?

您的点从蓝色变为黄色的原因是因为它们使用默认颜色图:parula. There are 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] 是白色。将前两个元素保留为零,并让第三个 运行 从 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