【发布时间】:2021-05-13 03:36:51
【问题描述】:
我在下面使用 matplotlib 创建了一个饼图:
import matplotlib.pyplot as plt
labels = ['dogs','cats','birds','fish']
sizes = [34, 24,18,13]
pie = plt.pie(sizes,autopct='%1.1f%%', startangle=90)
plt.axis('equal')
plt.legend( loc = 'right', labels=labels)
plt.show()
有没有办法将这些百分比放在图例中,以便图例显示为:
狗,34%
猫,24%
鸟类,18%
鱼,13%
我知道我可以将“标签”更改为以最快和最优雅的方式阅读上述内容,但是如果您在运行代码之前不知道“大小”怎么办?
【问题讨论】:
标签: python matplotlib charts