As one can see in this sample code since 0 is somewhere in the spectrum it is hard to trace which points are negative and which are positive. Although my real plot is more contiguous I wonder if there is a way to seperate negative and postivie values in these clorplots; for example how can I use two different spectrum of colours for positive and negative values.
import numpy as np
from matplotlib import pyplot as plt
a=np.random.randn(2500).reshape((50,50))
plt.imshow(a,interpolation='none')
plt.colorbar()
plt.show()
EDIT With the help of @MultiVAC and looking for solutions I came across this.
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.colors import BoundaryNorm
a=np.random.randn(2500).reshape((50,50))
# define the colormap
cmap = plt.cm.jet
# extract all colors from the .jet map
cmaplist = [cmap(i) for i in range(cmap.N)]
# create the new map
cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)
# define the bins and normalize
bounds = np.linspace(np.min(a),np.max(a),5)
norm = BoundaryNorm(bounds, cmap.N)
plt.imshow(a,interpolation='none',norm=norm,cmap=cmap)
plt.colorbar()
plt.show()
Still I don't know how to differentiate zero!