I have a barchart in Seaborn, and want to colour specific bars based upon the value of a categorical variable, y.
data = {'symbol': ['apple', 'banana', 'pear', 'aubergine'],
'value': [7, 5,6,3]}
df_c = pd.DataFrame(data)
fig, ax = plt.subplots(figsize=(5,10))
g = sns.barplot(data=df_c.head(50), y='symbol', x= 'value',color='black', ci=None)
ax.patches[35].set_facecolor('red')
I have a (bad) solution that lets me colour a bar by its position in the list (e.g. I count down and apply ax.patches
with a slice, but what I'd ideally like to be able to do is pass a list containing the categorical values of y, e.g. ['apple', 'banana'...]
Is this an option with a Seaborn barplot?