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

问题描述 投票:-1回答:1

我无法更改条形图中每个条形图的颜色,我想将“管理和支持人员”,“其他”更改为不同的颜色帮助..我当前的代码是

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

python python-3.x numpy dataframe matplotlib
1个回答
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()

得到它了

© www.soinside.com 2019 - 2024. All rights reserved.