Mis*_*cha 2 python matplotlib seaborn
我想将 autopct 文本更改为粗体和白色。
\n\n如果我在 ax1.pie(..) 中插入 textprops={\'color\':\'white\', \'weight\':\'bold\', \'fontsize\':12.5} ,标签就会消失。
\n\n有人能帮助我吗?
\n\nsizes1 = [3, 19]\nexplode1 = (0, 0.05)\n\nfig, (ax1, ax2) = plt.subplots(1,2, figsize=(10,10))\nlabels = (\'CRD = 1\', \'CRD = 0\')\n\n#fig1, ax1 = plt.subplots()\nax1.pie(sizes1,explode= explode1, labels=labels, autopct=\'%1.1f%%\',\n shadow=False,startangle=40, colors=(\'tab:red\', \'tab:blue\'))\nax1.set_title(\'Frauen\', fontdict={\'fontsize\': 17}, y=0.8)\n\nax1.axis(\'equal\')\n\nsizes2 = [10, 24]\nexplode2 = (0, 0.05)\n\n\nax2.pie(sizes2, labels=labels, autopct=\'%1.1f%%\',\n shadow=False,explode = explode2, startangle=345, colors=(\'tab:red\',\'tab:blue\'), )\nax2.set_title(\'M\xc3\xa4nner\', fontdict={\'fontsize\': 17}, y=0.8)\nax2.axis(\'equal\')\nRun Code Online (Sandbox Code Playgroud)\n\n饼图
\n\n\n由于它textprops适用于标签和自动百分比文本,因此您需要在函数外部设置自动百分比文本的格式pie。
import matplotlib.pyplot as plt
sizes1 = [3, 19]
explode1 = (0, 0.05)
labels = ('CRD = 1', 'CRD = 0')
fig1, ax1 = plt.subplots()
_, _, autopcts = ax1.pie(sizes1,explode= explode1, labels=labels, autopct='%1.1f%%',
shadow=False,startangle=40, colors=('tab:red', 'tab:blue'))
plt.setp(autopcts, **{'color':'white', 'weight':'bold', 'fontsize':12.5})
ax1.set_title('Frauen', fontdict={'fontsize': 17})
plt.show()
Run Code Online (Sandbox Code Playgroud)