lundi 7 juillet 2014

Matplotlib colorbar with a histogram


Vote count:

0




I made a histogram of array x with each bar color-coded according to the average of another property y in that bin. How can I make an associated colorbar?



norm = matplotlib.colors.Normalize(vmin=np.min(y), vmax=np.max(y))
cmap = cm.jet
m = cm.ScalarMappable(norm=norm, cmap=cmap)

fig = plt.figure()
n, bins, patches= plt.hist(x, bins = np.arange(0,max_x) + 0.5)
for i in range(np.size(patches)):
plt.setp(patches[i],color=m.to_rgba(y[i]))
plt.colorbar(norm=norm,cmap=cmap)
plt.show()


This colorbar returns an error message " No mappable was found to use for colorbar creation. First define a mappable such as an image (with imshow) or a contour set (with contourf)."



asked 32 secs ago

Cokes

153





Aucun commentaire:

Enregistrer un commentaire