I'm trying to plot a one-dimensional array as a pcolormesh (so the color varies along the x-axis, but is constant in the y-axis for each x). But my data has some bad values, so I'm using a masked array and a customized colormap with masked values set to blue:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import copy
a = np.array([3, 5, 10, np.inf, 5, 8])
a = np.ma.masked_where(np.isinf(a), a)
imdata = np.vstack((a, a))
myhot = copy.copy(cm.hot)
myhot.set_bad('b', 1)
fig, ax = plt.subplots()
im = ax.pcolormesh(imdata, cmap=myhot)
plt.colorbar(im)
plt.show()
It works fine if I don't have the np.inf
value, but I just get a blank plot if I do. I seem to have misunderstood something about the way set_bad
works because I get an additional warning:
RuntimeWarning: invalid value encountered in true_divide
resdat /= (vmax - vmin)
What should I be doing to get the effect I want?