gpt4 book ai didi

python - 如何强制 python 在饼图中显示整个标签

转载 作者:行者123 更新时间:2023-11-30 22:59:13 25 4
gpt4 key购买 nike

我想做一个饼图,但是python似乎切断了左侧和右侧的标签。有没有办法强制显示所有标签?这是我制作情节的方法

    import matplotlib.pyplot as plt

plt.clf()
# get all the groups from the database
tests ...

plt.axes([0.1, 0.1, 0.6, 0.6])
# The slices will be ordered and plotted counter-clockwise.
fracs = [test for test in tests]
labels = ...

explode = [ 0 everywhere ]
plt.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.title('title', y=1.15)

plt.savefig(store path "_pie.png")

情节如下

enter image description here

有谁知道如何避免标签被切断?谢谢卡尔

最佳答案

您可以尝试在 savefig 命令中使用 bbox_inches='tight' 或 plt.gca().tight_layout() 作为单独的命令。

关于python - 如何强制 python 在饼图中显示整个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840108/

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