【问题标题】:Matlab custom colormap with only 3 colorsMatlab自定义颜色图只有3种颜色
【发布时间】:2014-07-08 11:02:17
【问题描述】:

只是想检查是否可以制作只有 3 种颜色的自定义颜色图? (不需要渐变)。

示例:数据范围为0-100

  • 所以0-33 是一种颜色,
  • 34-67 是另一种颜色,
  • 68-100 是另一种颜色。

【问题讨论】:

    标签: matlab plot color-mapping


    【解决方案1】:

    只需使用三行的颜色图。每行根据 R、G、B 分量定义一种颜色。

    A = randi(100,16,16); %// example data
    imagesc(A) %// display matrix as image
    colormap([1 0 0; 0 1 0; 0 0 1]) %// apply colormap
    colorbar %// show color bar
    

    这定义了颜色之间均匀间隔的阈值。如果您需要更多控制,则需要超过三行,并重复一些颜色。例如,

    colormap([1 0 0; 1 0 0; 0 1 0; 0 0 1]) %// apply colormap
    

    将为第一种颜色定义 50% 的阈值,为第二种颜色定义 75%,为第三种颜色定义 100%。

    【讨论】:

      【解决方案2】:

      举个例子:

      % some matrix with integer values in the range [0,100]
      Z = peaks;
      Z(:) = round((Z(:)-min(Z(:))) ./ range(Z(:))*100);
      
      % show as image (with scaled color mapping)
      image(Z, 'CDataMapping','scaled')
      caxis([0 100])    % set axes CLim property
      colormap(eye(3))  % set figure Colormap property
      colorbar          % show colorbar
      

      请注意,颜色被缩放到 [0 100] 范围,该范围映射到当前图形的颜色图(我们设置为仅三种颜色)。

      【讨论】:

        【解决方案3】:

        按照这个例子:How to create a custom colormap programmatically?,但你可以使用R = ones(50,1)*t(1)而不是R = ones(50,1)*t(1)

        甚至更简单:

        如果颜色 1 是 t1 = [r1, g1, b1] 等,那么

        map(1:34, :) = repmat(t1, 33, 1)
        map(35:68, :) = repmat(t2, (67-34), 1)
        

        等等……

        map(1:34, :) = bsxfun(@times, t, ones(33,3)) 等等……

        【讨论】:

          【解决方案4】:

          查看我的答案here

          您可以使用该代码并决定是否在值之间进行插值,它只有 2 行代码。

          原始帖子中显示的 GYR 切割颜色图的结果图像。

          【讨论】:

            猜你喜欢
            • 2013-08-12
            • 1970-01-01
            • 2013-06-21
            • 1970-01-01
            • 2016-12-09
            • 2020-07-28
            • 1970-01-01
            • 2013-12-11
            • 1970-01-01
            相关资源
            最近更新 更多