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

后端 未结 4 1519
终归单人心
终归单人心 2020-12-25 15:36

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 analyti

4条回答
  •  Happy的楠姐
    2020-12-25 16:00

    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")

提交回复
热议问题