如何在不干扰文本标签颜色的情况下,将饼图中百分比标签的颜色更改为白色?

2024-05-16 12:02:43 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用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')

enter image description here


Tags: 文本sizelabels颜色countplt标签cmap