I want to plot a simple 1D histogram where the bars should follow the color-coding of a given colormap.
Here\'s an MWE:
import numpy as
While it isn't what you asked for, if someone else stumbles across this (like I did) looking for the way to do the coloration by height of the bins instead of order, the following code based on Bas's answer would work:
import numpy as np
import matplotlib.pyplot as plt
Ntotal = 1000
data = 0.05 * np.random.randn(Ntotal) + 0.5
cm = plt.cm.get_cmap('RdYlBu_r')
n, bins, patches = plt.hist(data, 25, normed=1, color='green')
# To normalize your values
col = (n-n.min())/(n.max()-n.min())
for c, p in zip(col, patches):
plt.setp(p, 'facecolor', cm(c))
plt.show()