【问题标题】:how can I enforce python to show the entire label in a pie plot如何强制 python 在饼图中显示整个标签
【发布时间】:2016-03-07 09:24:26
【问题描述】:

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

情节是这样的

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

【问题讨论】:

    标签: python matplotlib plot pie-chart


    【解决方案1】:

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

    【讨论】:

    • 是的,这样的作品,但它确实扭曲了饼图,使其非圆形......我想有一个选项,只是在左侧和右侧添加空间以显示所有文字?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 2022-01-21
    • 2012-12-26
    相关资源
    最近更新 更多