Don't show zero values on 2D heat map
<p>I want to plot a 2D map of a sillicon wafer dies. Hence only the center portion have values and corners have the value 0. I'm using matplotlib's plt.imshow to obtain a simple map as follows:</p>

<pre><code>data = np.array([[ 0. ,  0. ,  1. ,  1. ,  0. ,  0. ],
       [ 0. ,  1. ,  1. ,  1. ,  1. ,  0. ],
       [ 1. ,  2. ,  0.1,  2. ,  2. ,  1. ],
       [ 1. ,  2. ,  2. ,  0.1,  2. ,  1. ],
       [ 0. ,  1. ,  1. ,  1. ,  1. ,  0. ],
       [ 0. ,  0. ,  1. ,  1. ,  0. ,  0. ]])

plt.figure(1)
plt.imshow(data ,interpolation='none')
plt.colorbar()
</code></pre>

<p>And I obtain the following map:
<a href="http://i.stack.imgur.com/NdOB3.png" rel="nofollow"><img src="http://i.stack.imgur.com/NdOB3.png" alt="enter image description here"></a></p>

<p>Is there any way to remove the dark blue areas where the values are zeros while retaining the shape of the 'wafer' (the green, red and lighter blue areas)? Meaning the corners would be whitespaces while the remainder retains the color configuration. </p>

<p>Or is there a better function I could use to obtain this?</p>

<p>There are two ways to get rid of the dark blue corners:</p>

<p>You can flag the data with zero values:</p>

<pre><code>data[data == 0] = np.nan
plt.imshow(data, interpolation = 'none', vmin = 0)
</code></pre>

<p>Or you can create a masked array for <code>imshow</code>:</p>

<pre><code>data_masked = np.ma.masked_where(data == 0, data)
plt.imshow(data_masked, interpolation = 'none', vmin = 0)
</code></pre>

<p>The two solutions above both solve your problem, although the use of masks is a bit more general.</p>

<p>If you want to retain the exact color configuration you need to manually set the <code>vmin</code>/<code>vmax</code> arguments for plotting the image. Passing <code>vmin = 0</code> to <code>plt.imshow</code> above makes sure that the discarded zeros still show up on the color bar.
<a href="http://i.stack.imgur.com/iIjpF.png" rel="nofollow"><img src="http://i.stack.imgur.com/iIjpF.png" alt="masked-imshow"></a></p>

python matplotlib