How to set a different color to the largest bar in a seaborn barplot?

pmdaly picture pmdaly · Jun 26, 2015 · Viewed 22.8k times · Source

I'm trying to create a barplot where all bars smaller than the largest are some bland color and the largest bar is a more vibrant color. A good example is darkhorse analytic's pie chart gif where they break down a pie chart and end with a more clear barplot. Any help would be appreciated, thank you!

Answer

iayork picture iayork · Jun 26, 2015

Just pass a list of colors. Something like

values = np.array([2,5,3,6,4,7,1])   
idx = np.array(list('abcdefg')) 
clrs = ['grey' if (x < max(values)) else 'red' for x in values ]
sb.barplot(x=idx, y=values, palette=clrs) # color=clrs)

enter image description here

(As pointed out in comments, later versions of Seaborn use "palette" rather than "color")