matplotlib pyplot make certain color transparent
For this, a subset has to become bad values, and a cmap has to set what to do with them.
my_cmap = copy.copy(plt.cm.get_cmap('gray')) # get a copy of the gray color map my_cmap.set_bad(alpha=0) # set how the colormap handles 'bad' values plt.imshow(thing, cmap=my_cmap)
As for bad values, I wrote a function similar to this to make them arbitrary:
def get_bad_values(matr, value=0): new_matr = matr.astype(np.float) new_matr[new_matr == value] = np.nan return new_matr
np.nan can only replace a
np.float, never an int!