您需要所谓的
ListedColorMap:
import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mpl# random datax = np.random.random_integers(0, 1, (10, 10))fig, ax = plt.subplots()# define the colorscmap = mpl.colors.ListedColormap(['r', 'k'])# create a normalize object the describes the limits of# each colorbounds = [0., 0.5, 1.]norm = mpl.colors.BoundaryNorm(bounds, cmap.N)# plot itax.imshow(x, interpolation='none', cmap=cmap, norm=norm)



