define your patches 有多种方式,color them as well 有多种方式。这是一种无需 for 循环即可创建坐标数据的方法,只需调用函数 patch 即可绘制和着色补丁:
x = [NaN 1 3 7 9 23 8]; %# Sample x data
y = [NaN 2 6 7 8 2 1]; %# Sample y data
z = [NaN 1 4 5 5 4 1]; %# Sample z data
N = numel(x); %# The number of sample data points
X = [x; x([1 1],[N 1:N-1]); x]; %# X coordinates (one patch per column)
Y = [y; y([1 1],[N 1:N-1]); y]; %# Y coordinates (one patch per column)
Z = [z; z([N 1:N-1]); zeros(2,N)]; %# Z coordinates (one patch per column)
C = round(63.*Z./max(Z(:)))+1; %# Color map index
map = [linspace(0,1,64).' ... %'# Color map (64 values spanning from
ones(64,2)]; %# white to cyan)
figure(); %# Open a new figure
patch(X,Y,Z,C,'FaceColor','interp',... %# Plot the patches
'EdgeColor','none');
colormap(map); %# Update color map
hold on; %# Add to the plot
line(X(1:2,:),Y(1:2,:),Z(1:2,:),... %# Plot the line
'Color','b','LineWidth',2);
view(3); %# Change the view
这将为您提供以下图,在最高值处为白色,在最低值处逐渐变为青色:
索引颜色映射的解释...
上面的变量 map 是一个 64×3 矩阵,其值介于 0 和 1 之间。每一行代表一个 RGB triplet,因此定义了一个唯一的颜色,从第 1 行的青色到第 64 行的白色。这用作图形颜色图。 C 中的人脸颜色数据是此颜色图中的一组行索引,Z 中的每个值对应一个。 Z 中的最小值映射到索引 1(颜色图中的青色),而最大值映射到索引 64(颜色图中的白色)。