matplotlib percent label position in pie chart

PythonMatplotlib

Python Problem Overview


Is there a way to change the default position of the percent label in a matplot lib pie chart?

Here is an example pie chart:

My pie chart

Which I have created using:

plt.pie(sizes, labels=labels, colors=colors, explode=explode, autopct='%1.0f%%')

Now I don't like how some percent labels are intruding on other sections teritory (actually the only perpitrator in this example is the 9m section). Ideally I would like such labels to be outside the pie chart with an arrow of some sort pointing to the section, or alternativly just outside the section.

Python Solutions


Solution 1 - Python

You can control the distance of the percents and labels from the center of the pie using pctdistance= and labeldistance=, try this on your code:

plt.pie(sizes, labels=labels, autopct='%1.0f%%', pctdistance=1.1, labeldistance=1.2)

You can also set a radius of the pie using radius= (by default is 1)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDanielView Question on Stackoverflow
Solution 1 - PythonAlvaro FuentesView Answer on Stackoverflow