2016-02-27 25 views
1

我想用“过渡facecolor”(我不知道正确的术语)在Matlab中给一个矩形上色,这意味着例如从地狱蓝转变为深蓝;你也可以把它解释为一个阴影(在这里你可以看到一个例子:Matlab中的“Transition-FaceColor”

http://il1.picdn.net/shutterstock/videos/620653/thumb/1.jpg?i10c=img.resize(height:160)

我能想象用颜色表来实现它,但我不知道如何应用它的文本注释像一个矩形。

是否有可能修改Matlab的标准(单色)的颜色以这样的方式?如果是这样,是否有人有一个基本的框架呢?

回答

0

您可以使用patch,它允许创建矩形具有内插的脸部颜色

然后,为了让脸色从深蓝色到亮蓝色,您必须定义自己的“蓝色”colormap

colormap应定义为一个(N x 3)RGB阵列:在你的情况下,必须设定为0前两列(对应于red和​​和具有所述第三列(blue的值)范围为(start_blue,end_blue)其中start_blue是你想要的最暗的蓝色级别,end_blue最亮(均必须01之间)。

% 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]) 

enter image description here

希望这有助于。

Qapla'

+0

太棒了!这正是我所期待的 - 你已经完美地描述了它。真的非常感谢你!你过去是否自己使用过这些代码,或者你是否为我创建了它?作为后者,我非常感谢它:)谢谢 –

+0

不客气,happu我一直在使用你。为了解决这个问题,你能否将答案标记为“已接受”。 –