Shading and masking over pcolor in matlab

Two questions actually, but I feel that they overlap, so I will ask them in one place (if that is the case).

I created pcolor in matlab using:

p = pcolor(Lon', Lat', data);

But now I want to add some information. I have a matrix maskthat has the same dimensions as the data, but 1s and 0s are populated. Where it contains 1, I would like to save the pixel in pcolor, and when it contains 0, delete it (don't just rotate the value to zero, which is not represented by a white pixel in my color map).

Secondly, I have a second matrix called β€œclipping”, which again contains 0s and 1s. Now I want to overlay any location represented by 1 with the edging effect.

The purpose of this is to create an image something like this: http://www.ipcc.ch/publications_and_data/ar4/wg1/en/figure-spm-7.html where the average value is colored, but areas where there is too much disagreement are highlighted, and areas where there is much agreement are β€œoutlined”.

Thanks in advance!

+3
source share
1 answer

The approach I would like to use is to use a mask for transparency. This is a bit more complicated for pcolor, because it does not allow you to set properties directly when creating a chart, but you can grab a handle and do it this way.

, hold on, pcolor , "plot" , .

Lon = (-179:1:180)'; %# comment for formatting'
Lat = -90:1:90;
data = randn(length(Lon),length(Lat)); #% generate random data
mask = randi(2,size(data))-1; #% generate a random mask (zeros and ones)
point_matrix = randi(4,size(data)-1)==4; #% random (logical) matrix
[r c]=find(point_matrix==1); %# get the coordinates of the ones
figure;
hold on;
#% save a handle to the surface object created by pcolor
h=pcolor(repmat(Lon ,1,length(Lat)),repmat(Lat,length(Lon),1),data);
#% set properties of that surface: use mask as alphadata for transparency
#% and set 'facealpha' property to 'flat', and turn off edges (optional)
set(h,'alphadata',mask,'facealpha','flat','edgecolor','none');
#% overlay black dots on the center of the randomly chosen tiles
plot(r-179.5,c-89.5,'.k')
+4

All Articles