您的分数从蓝色变为黄色的原因是因为它们使用默认颜色图: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