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

标签 python matplotlib plot pie-chart

我想做一个饼图,但是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/

相关文章:

python - pyplot step 函数不为第一个/最后一个点绘制水平

python - Pandas 如何转置数据并添加列名

Python for 循环内的异常处理

python - django 获取社会 token 形式 allauth

python - 无法从 '_png' 导入名称 'matplotlib'

python - 将两个 matplotlib figure.Figure 或 axes.Axes 对象合并为一个新对象

python - 如何使用 Matplotlib 制作具有光环效果的散点图?

python - 替换我的功能的更好方法?

python - matplotlib 中的散点图和组合极坐标直方图

python - 如何在 matplotlib 中使轴透明?