如何在matplotlib条形图(python)中更改/设置多个条形颜色

时间:2017-12-28 10:25:47

标签: python python-3.x numpy dataframe matplotlib

我无法更改条形图中每个条形的颜色 我想改变' Administrative&支持员工','其他'不同的颜色帮助.. 我目前的代码是

import seaborn as sns
sns.set()

ax1 = tt.plot(kind='bar', figsize=(20,10), fontsize=13)
#legend = plt.legend(loc=2, fontsize=8)
for tick in ax1.get_xticklabels():
    tick.set_rotation(0)

ax1.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
          fancybox=True, shadow=True, ncol=5)
# ax1 = plt.gca()
# leg = ax1.get_legend()
# leg.legendHandles[1].set_color('yellow')

plt.show()

output image

1 个答案:

答案 0 :(得分:0)

import seaborn as sns
sns.set()

ax1 = tt.plot(kind='bar', figsize=(20,10), fontsize=13, color = ['#1b9e77', '#a9f971', '#fdaa48'])

for tick in ax1.get_xticklabels():
    tick.set_rotation(0)

ax1.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
          fancybox=True, shadow=True, ncol=5)


plt.show()

得到它