gpt4 book ai didi

python - 如何在python中的饼图上设置标签大小

转载 作者:IT老高 更新时间:2023-10-28 21:52:55 29 4
gpt4 key购买 nike

我想在 python 的饼图中使用小尺寸的标签以提高可见性这是代码

import matplotlib.pyplot as plt

frac=[1.40 , 10.86 , 19.31 , 4.02 , 1.43 , 2.66 , 4.70 , 0.70 , 0.13 , 1.48, 32.96 , 1.11 , 13.30 , 5.86]
labels=['HO0900344', 'HO0900331', 'HO0900332', 'HO0900354',
'HO0900358', 'HO0900374', 'HO0900372', 'HO0900373',
'HO0900371', 'HO0900370', 'HO0900369', 'HO0900356',
'HO0900353', 'HO0900343']

fig = plt.figure(1, figsize=(6,6))
ax = fig.add_subplot(111)
ax.axis('equal')
colors=('b', 'g', 'r', 'c', 'm', 'y', 'burlywood', 'w')
ax.pie(frac,colors=colors ,labels=labels, autopct='%1.1f%%')
plt.show()

最佳答案

更改饼图字体大小的最简单方法是直接通过 textprops argumentpie() 函数中。使用上面的代码添加它:

ax.pie(frac, colors=colors ,labels=labels, 
autopct='%1.1f%%', textprops={'fontsize': 14})

这样您就可以传入具有所需字体大小(例如 14)的字典。不用弄乱 rcParams 或从函数调用返回值。

关于python - 如何在python中的饼图上设置标签大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7082345/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com