give NaNs a specific color in a matplotlib figure
July 6th, 2011 by Lawrence David
to give NaNs their own specific color in a plot, use a masked array. for example, the code below will color NaNs white:
import numpy.ma
import pylab as pl
masked_X = numpy.ma.array(X,mask=np.isnan(X))
cmap.set_bad(‘w’,1.)
fig, ax = pl.subplots(1)
im1 = ax.matshow(masked_X)