【问题标题】:How do I change the color of percentage label to be white in pie chart without interfering the text label color?如何在饼图中将百分比标签的颜色更改为白色而不干扰文本标签颜色?
【发布时间】:2021-09-08 12:16:42
【问题描述】:

如何使用 matplotlib 将饼图中的百分比标签颜色更改为白色而不干扰文本标签颜色?当我编辑 textprops={'size': 'x-large','color':'w'} 时,文本颜色会变成白色,与背景没有对比。

labels = df01['new_sentiment']
count = df01['count']

cmap = plt.get_cmap('Greys')
colors = list(cmap(np.linspace(0.45, 0.85, len(count))))

fig1, ax1 = plt.subplots()
ax1.pie(count, labels=labels, autopct='%1.1f%%', textprops={'size': 'x-large'}, colors=colors)

ax1.axis('equal')
plt.title('7D-prior-PM_sem_sen', pad=30)
plt.savefig('04_7D-prior-PM_sem_sen.tiff', dpi=300, format='tiff', bbox_inches='tight')

【问题讨论】:

    标签: python matplotlib colors pie-chart


    【解决方案1】:

    您可以像这样更改内部标签的颜色:

    _,_,m = ax1.pie(count, labels=labels, autopct='%1.1f%%', textprops={'size': 'x-large'}, colors=colors)
    [m[i].set_color('white') for i in range(len(m))]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      相关资源
      最近更新 更多