title: Contourf and NaNs (how to make white regions transparent)
body: <p>I'm trying to make a <code>contourf</code> plot but certain areas of the data array have NaNs (only in the data matrix, the x and y meshgrid matrices are full). I'd like these NaNs to be transparent, and they are for NaNs on the boundary of the rectangle. But, contiguous NaN regions inside the data matrix are white instead of transparent. Below is an example:</p>
  
  <p>Code:</p>
  
  <pre><code>[X Y] = meshgrid(10:50);
  Z = X.*Y;
  Z(10:30,10:30) = NaN;
  figure
  imshow(uint8(repmat(1:4:240,[60,1,3])));
  hold on;
  contourf(X,Y,Z);
  colormap jet;
  </code></pre>
  
  <p>Output:</p>
  
  <p><img src="https://i.stack.imgur.com/zMH1x.jpg" alt="enter image description here"></p>
  
  <p>Hint:</p>
  
  <p>Appending the above code with:</p>
  
  <pre><code>% Find Face
  set(findobj(h,'FaceColor',[1 1 1]),'FaceAlpha',0))
  </code></pre>
  
  <p>Will find the white patch object and set it transparent. Unfortunately, the patch underneath is full:</p>
  
  <p><img src="https://i.stack.imgur.com/1T91s.jpg" alt="enter image description here"></p>
  
  <p>Update: Taking the <code>NaN</code> region and superimposing the background image results in:</p>
  
  <p><img src="https://i.stack.imgur.com/JvJKG.jpg" alt="enter image description here"></p>
  
  <p>As you can see it doesnt cover the entire image. If I use <code>imdilate</code> it gets rid of the white area but at the same time also destroys the black border as well as a little bit of the data.</p>