您可以使用patch
,它允许创建矩形具有内插的脸部颜色
然后,为了让脸色从深蓝色到亮蓝色,您必须定义自己的“蓝色”colormap
。
的colormap
应定义为一个(N x 3)
RGB
阵列:在你的情况下,必须设定为0
前两列(对应于red
和和具有所述第三列(blue
的值)范围为(start_blue,end_blue)
其中start_blue
是你想要的最暗的蓝色级别,end_blue
最亮(均必须0
和1
之间)。
% Define the rectangle: lower left x, lower left y, width, height
x_rect=1;
y_rect=1;
width=10;
height=5;
% Define the patch vertices and faces
verts=[x_rect y_rect;x_rect y_rect+height; ...
x_rect+width y_rect+height;x_rect+width y_rect];
faces=[1 2 3 4];
% Define the color: the higher the brighter
col=[0; 0; 4; 4];
figure
% Create the new blue colormap
b=0.7:.01:1;
cm1=[zeros(length(b),2) b']
% Set the new colormap
colormap(cm1)
% Plot the patch
patch('Faces',faces,'Vertices',verts,'FaceVertexCData',col,'FaceColor','interp');
作为替代方案,您可以创建矩形为surf
,然后,如上定义您自己的colormap
。
% Define the rectangle:
x_rect=1;
y_rect=1;
width=10;
height=5;
% Build a patch
xp=[x_rect:x_rect+width];
yp=[y_rect:y_rect+height];
% Get the number of points
n_xp=length(xp);
n_yp=length(yp);
% Create the grid
[X,Y]=meshgrid(xp,yp);
% Define the z values
Z=ones(size(X));
% Create the color matrix as uniformly increasing
C=repmat(linspace(1,10,n_xp),n_yp,1)
% Create the new blue colormap
start_blue=0.5;
end_blue=1;
b=start_blue:.01:end_blue;
cm1=[zeros(length(b),2) b']
% Set the new colormap
colormap(cm1)
% Plot the rectangle as a "surf"
surf(X,Y,Z,C)
shading interp
xlabel('X Axis')
ylabel('Y Axis')
view([0 90])
xlim([0 13])
ylim([0 9])
daspect([1 1 1])
希望这有助于。
Qapla'
太棒了!这正是我所期待的 - 你已经完美地描述了它。真的非常感谢你!你过去是否自己使用过这些代码,或者你是否为我创建了它?作为后者,我非常感谢它:)谢谢 –
不客气,happu我一直在使用你。为了解决这个问题,你能否将答案标记为“已接受”。 –