【发布时间】:2014-07-08 11:02:17
【问题描述】:
只是想检查是否可以制作只有 3 种颜色的自定义颜色图? (不需要渐变)。
示例:数据范围为0-100,
- 所以
0-33是一种颜色, -
34-67是另一种颜色, - 和
68-100是另一种颜色。
【问题讨论】:
标签: matlab plot color-mapping
只是想检查是否可以制作只有 3 种颜色的自定义颜色图? (不需要渐变)。
示例:数据范围为0-100,
0-33 是一种颜色,34-67 是另一种颜色,68-100 是另一种颜色。【问题讨论】:
标签: matlab plot color-mapping
只需使用三行的颜色图。每行根据 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%。
【讨论】:
举个例子:
% 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] 范围,该范围映射到当前图形的颜色图(我们设置为仅三种颜色)。
【讨论】:
按照这个例子: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))
等等……
【讨论】:
【讨论】: