【问题标题】:Scatter plot with colors from dark to bright颜色从暗到亮的散点图
【发布时间】:2020-01-20 04:49:07
【问题描述】:

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

这是我的代码:

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

使用结果图。

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

【问题讨论】:

    标签: matlab colors matlab-figure scatter


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 2014-09-10
      相关资源
      最近更新 更多