图上有多个彩色阴影区域,每个区域都有一个由方程式定义的透明度梯度?

时间:2020-06-28 10:03:35

标签: matlab gradient transparency alpha colormap

使用Matlab,我试图将多个阴影区域添加到一些数据点的绘图中。我希望阴影区域每个都有一个透明度梯度,并且希望每个透明度的分布都由我提供的一些输入方程式给出。

对于测试,我试图通过为阴影数据输入高斯分布,然后使用imagesc()将其添加到绘图中来使其工作。这是代码的最小示例:

%%% some dummy data points
x = linspace(0,1,10);
y1 = ones(10,1)*0.7;
y2 = ones(10,1)*0.3;

%%% create data to describe distribution of shaded areas
x_area = linspace(0,1,1000);y_area = x_area;
[X_area,Y_area] = meshgrid(x_area,y_area);
Z1 = exp(-(Y_area-0.3).^2/(2*0.07^2)); % distribution is Gaussian for testing
Z2 = exp(-(Y_area-0.7).^2/(2*0.15^2));

%%% appearance properties of shaded areas
start_color_1 = [0 0 1]; % blue
start_color_2 = [1 0 0]; % red
alpha_1 = 0.2;
alpha_2 = 0.4;

figure;hold all

h1 = imagesc(x_area,y_area,Z1);
colormap([linspace(1,start_color_1(1),256)' linspace(1,start_color_1(2),256)' linspace(1,start_color_1(3),256)']);
h1.AlphaData = alpha_1;

h2 = imagesc(x_area,y_area,Z2);
colormap([linspace(1,start_color_2(1),256)' linspace(1,start_color_2(2),256)' linspace(1,start_color_2(3),256)']);
h2.AlphaData = alpha_2;

p = plot(x,y1,'o',x,y2,'s');

这会产生以下类型的事物:

enter image description here

但是,正如您所看到的,我的start_colour_2变量并未受到尊重,因为第二次使用时色图被覆盖。我希望最上面的乐队是蓝色的并且可以独立控制。

是否有更好的方法可以实现此目标,例如使用补丁或区域对象?还是imagesc路线最合适,我需要以某种方式为每个路线修复色彩图?

感谢您的帮助

(我的Matlab版本是R2017a)

0 个答案:

没有答案