2012-02-26 193 views

回答

3

使用ListedColormapBoundaryNorm

import numpy as np 
import matplotlib as mpl 
from matplotlib import pyplot 
data = np.floor(np.random.random((10,10)) * 6) 
cmap = mpl.colors.ListedColormap(['w', 'b', 'g', 'y', '#ff8c00', 'r']) 
norm = mpl.colors.BoundaryNorm([0,1,2,3,4,5,6], cmap.N) 
pyplot.imshow(data, cmap=cmap, norm=norm, interpolation='none') 
pyplot.colorbar() 
pyplot.show() 

使用ListedColormap的一些例子:colorbarsmulticolored lines