To make the elements of different colors, assign them different values:
my_array = diag([1,1,1,2,2,2,3,3,3])
To specify colors, try:
from matplotlib.colors import ListedColormap, NoNorm cmap = ListedColormap(['#E0E0E0', '#FF8C00', '#8c00FF', '#00FF8C']) pcolor(my_array,cmap=cmap,norm=NoNorm())
The norm=NoNorm() argument avoids scaling the matrix values, so 0 gets the first color in the list, 1 gets the second color, etc.
Jouni K. Seppänen
source share