I've plot a barplot in seaborn using the follow function:
ax = sns.barplot(x='Year', y='Value', data=df)
Now I'd like to color each bar according to the following rule:
percentages = []
for bar, yerr_ in zip(bars, yerr):
low = bar.get_height() - yerr_
high = bar.get_height() + yerr_
percentage = (high-threshold)/(high-low)
if percentage>1: percentage = 1
if percentage<0: percentage = 0
percentages.append(percentage)
I believe I can access the bars through ax.patches, which returns a set of rectangles:
for p in ax.patches:
height = p.get_height()
print(p)
>> Rectangle(-0.4,0;0.8x33312.1)
>> Rectangle(0.6,0;0.8x41861.9)
>> Rectangle(1.6,0;0.8x39493.3)
>> Rectangle(2.6,0;0.8x47743.6)
However, I don't know how to retrieve the yerr data calculated by seaborn/matplotlib.