carl
carl

Reputation: 4426

how can I enforce python to show the entire label in a pie plot

I want to make a pie plot, but python seems to cutoff the labels on the left and right. Is there a way to enforce that all labels are shown? Here is how I make the plot

    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")

and the plot looks like this

enter image description here

does anyone know how to avoid the cutoff of labels? thanks carl

Upvotes: 1

Views: 890

Answers (1)

dinos66
dinos66

Reputation: 706

You could try using the bbox_inches='tight' in the savefig command or plt.gca().tight_layout() as a separate one.

Upvotes: 3

Related Questions