I am trying to use imshow in matplotlib to plot data as a heat map, but some of them are NaN. I would like NaNs to appear as a special color not found in the color palette.
Example:
import numpy as np import matplotlib.pyplot as plt f = plt.figure() ax = f.add_subplot(111) a = np.arange(25).reshape((5,5)).astype(float) a[3,:] = np.nan ax.imshow(a, interpolation='nearest') f.canvas.draw()
The resulting image suddenly turns blue (the lowest color in the color map of the jet). However, if I do this:
ax.imshow(a, interpolation='nearest', vmin=0, vmax=24)
- then I get something better, but the NaN values ββare drawn in the same color as vmin ... Is there an elegant way that I can set NaNs using a special color (for example: gray or transparent)?
python matplotlib nan
Adam Fraser Apr 05 2018-10-14T00: 00Z
source share