How can I apply alpha on pcolor without altering the data
82 views (last 30 days)
Hi, I want to create a mask on my pcolor plot which will make some part of the data transparent and the rest will remain clear. I tried to do this by creating two matrixes with NaN values wherever I wanted to mask it, one is a negative of the other, making one of them transparent and placing one on the other (by simple hold on operation). I created a test.script to show does it work or better how doesn't it work: Alpha changes the shape of my mask, if you can find any solution for that I will be vey grateful.
% my real data
x=1:171; y=1:81; [X,RR]=meshgrid(x,y);
% creating mask (in reality is much more complicated)
% creating reversed mask
for n=1:81 for m=1:171 if mask(n,m)==1 revmask(n,m)=0; elseif mask(n,m)==0 revmask(n,m)=1; end end end
% creating data matrix with mask
for n=1:81 for m=1:171 if mask(n,m)==1 DD(n,m)=RR(n,m); else DD(n,m)=NaN; end end end
% creating data matrix with reversed mask
for n=1:81 for m=1:171 if revmask(n,m)==1 GG(n,m)=RR(n,m); else GG(n,m)=NaN; end end end % plotting
e1=pcolor(x,y,GG); caxis([1 81]) set(e1,'facealpha',0.3)
pcolor(x,y,DD) caxis([1 81])
e1=pcolor(x,y,GG); set(e1,'Facealpha',0.3) caxis([1 81]) hold on e2=pcolor(x,y,DD); set(e2,'facealpha',1) hold off
Supreeth Subbaraya on 13 Aug 2014
This seems to be an issue with the renderer. Change the renderer to zbuffer or painters and see if the result is what you expect. To change the renderer use the set command.
Note that the transparency is not supported by the zbuffer or painters.
And if you do not need the mesh lines on your image, you can add the following line at the end of your code.
Supreeth Subbaraya on 14 Aug 2014
Before the "hold off" line in your code instead of the command,
I guess it should be,
The transparency value should be 0.3 instead of 1.