如何为seaborn barplot中的最大条形设置不同的颜色? [英] How to set a different color to the largest bar in a seaborn barplot?

查看:685
本文介绍了如何为seaborn barplot中的最大条形设置不同的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个条形图,其中所有小于最大条形的条形都是淡淡的颜色,而最大的条形则是更鲜艳的颜色.一个很好的例子是Darkhorse analytics的饼图gif ,分解饼图并以更清晰的条形图结束.任何帮助将不胜感激,谢谢!

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!

推荐答案

只需传递颜色列表即可.像

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)

(如评论中所指出,Seaborn的更高版本使用调色板"而不是颜色")

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

这篇关于如何为seaborn barplot中的最大条形设置不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆