只想检查是否可以用3种颜色制作自定义色彩图? (不需要渐变)。Matlab只有3种颜色的自定义色彩图
示例:从0-100
数据范围,
- 所以
0-33
是一种颜色, 34-67
是另一种颜色,- 和
68-100
是另一种颜色。
只想检查是否可以用3种颜色制作自定义色彩图? (不需要渐变)。Matlab只有3种颜色的自定义色彩图
示例:从0-100
数据范围,
0-33
是一种颜色,34-67
是另一种颜色,68-100
是另一种颜色。只需使用一个颜色表三行。每行按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%。
按照这个例子:How to create a custom colormap programmatically?但不是R = linspace(0,t(1),50)'
你会使用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))
等等
借此例如:
% 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],该范围被映射到当前的人物的颜色表(我们设置为仅三种颜色)。