I want to color the rectangles of a horizontal bar plot based on their value as reflected in a colormap I have. Is there a way to iterate over each rectangle and make the color reflect its value on the colormap?
Here is what I'm working with if you're interested
I have my x and y values and put them into a normal horizontal barplot like so, and I have some labels at the end denoting values like so:
plt.barh(x, y)
for i, v in enumerate(y):
ax.text(v + 1, i - .15 , str(v))
The horizontal bar graph looks like this:
Here is the colormap I want to use:
fig, ax = plt.subplots(figsize=(0.5, 16))
colorBar = plt
fig.subplots_adjust(bottom=0.5)
cmap = mpl.cm.YlGn
norm = mpl.colors.Normalize(vmin=1, vmax=100)
cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
norm=norm,
orientation='vertical')
fig.show()