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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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)
(As pointed out in comments, later versions of Seaborn use "palette" rather than "color")
回答2:
[Barplot case] If you get data from your dataframe you can do these:
labels = np.array(df.Name)
values = np.array(df.Score)
clrs = ['grey' if (x < max(values)) else 'green' for x in values ]
#Configure the size
plt.figure(figsize=(10,5))
#barplot
sns.barplot(x=labels, y=values, palette=clrs) # color=clrs)
#Rotate x-labels
plt.xticks(rotation=40)