masked_array = np.ma.masked_where(a == -999, a)
cmap = matplotlib.cm.jet
cmap.set_bad('w', 1.0)
ax.imshow(masked_array, interpolation='nearest', cmap=cmap)
How can I plot NaN values as a special color with imshow in matplotlib?