I want to obtain grid with values mapped onto colors. It should be like a probability distribution, where 1.0 corresponds to black and 0.0 to white, grey in between. Reading the answers here I try it out for my case:
from matplotlib import mpl,pyplot
import numpy as np
zvals = np.zeros((10,5))
zvals[5,1] = 0.5
zvals[5,2] = 0.3
zvals[5,3] = 0.7
zvals[5,4] = 5.8
cmap = mpl.colors.LinearSegmentedColormap.from_list('my_colormap',['white','black'],256)
img = pyplot.imshow(zvals,interpolation='nearest', cmap = cmap)
pyplot.colorbar(img,cmap=cmap)
pyplot.show()
I see the problem, because linear mapping treats maximal value from the 2D array as black. But array not necessarily contains value 1.0.
How to set hard boundaries of 0.0 and 1.0, with smooth transition in between?