"Transition-FaceColor" 在 Matlab 中
"Transition-FaceColor" in Matlab
我想在 Matlab 中用 "transition facecolor"(我不知道正确的术语)给一个矩形上色,意思是例如从地狱蓝到深蓝色的过渡;你也可以将它解释为阴影(在这里你可以看到一个例子:
http://il1.picdn.net/shutterstock/videos/620653/thumb/1.jpg?i10c=img.resize(height:160)
我可以想象通过使用颜色图来实现它,但我不知道如何将它应用到像矩形这样的文本注释上。
是否可以通过这种方式修改 Matlab 的标准(单色)颜色?如果是这样,有人有它的基本框架吗?
您可以使用 patch
创建矩形,它允许插值面部颜色。
然后,为了让面部颜色从深蓝色到亮蓝色,您必须定义自己的 "blue" colormap
.
colormap
应定义为 (N x 3)
RGB
数组:在您的情况下,您必须将前两列设置为 0
(对应于 red
和 green
并且第三列(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'
我想在 Matlab 中用 "transition facecolor"(我不知道正确的术语)给一个矩形上色,意思是例如从地狱蓝到深蓝色的过渡;你也可以将它解释为阴影(在这里你可以看到一个例子:
http://il1.picdn.net/shutterstock/videos/620653/thumb/1.jpg?i10c=img.resize(height:160)
我可以想象通过使用颜色图来实现它,但我不知道如何将它应用到像矩形这样的文本注释上。
是否可以通过这种方式修改 Matlab 的标准(单色)颜色?如果是这样,有人有它的基本框架吗?
您可以使用 patch
创建矩形,它允许插值面部颜色。
然后,为了让面部颜色从深蓝色到亮蓝色,您必须定义自己的 "blue" colormap
.
colormap
应定义为 (N x 3)
RGB
数组:在您的情况下,您必须将前两列设置为 0
(对应于 red
和 green
并且第三列(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'