matlab colormap有三列

时间:2015-02-10 09:06:59

标签: matlab plot colormap

我想在matlab中绘制一个带有三列的颜色贴图。 我可以使用下面的plot3进行绘制,

x = [1 1 1 1 2 2 2 2 4 4 4 4 5 5 5 5 9 9 9 9]; 
y = [2 3 4 5 5 6 7 8 4 5 6 7 1 2 3 4 7 8 9 10];
z = [1 3 2 4 5 6 7 3 9 8 8 9 2 4 3 5 1 2 3 1];
plot3(x, y, z, 'o')

但是如何用三列绘制二维色彩图?

1 个答案:

答案 0 :(得分:3)

选项1:

如果我理解正确,你想绘制一个二维数组(比如m(x,y)),其中颜色由z给出。这是如何:

m=zeros(max(x),max(y));    % preallocate m according to values of x,y
m(sub2ind(size(m),x,y))=z; % assign z-values to the x,y coordinates
imagesc(m)                 % plot
colormap(pink(max(z)));    % set colormap with the dynamic range of z.
                           % you can replace it with jet or whatever...
colorbar                   % add a colorbar

enter image description here

选项2:

你真的只想从x,y,z创建RGB色彩映射:

cmap=[x(:) y(:) z(:)]./max([x(:);y(:);z(:)]);
imagesc(peaks(100)); 
colormap(cmap);

enter image description here