Python matplotlib 百分比标签在饼图中的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/21572870/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
matplotlib percent label position in pie chart
提问by Daniel
Is there a way to change the default position of the percent label in a matplot lib pie chart?
有没有办法更改 matplot lib 饼图中百分比标签的默认位置?
Here is an example 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.
现在我不喜欢某些百分比标签如何侵入其他部分领土(实际上,此示例中唯一的侵权者是 9m 部分)。理想情况下,我希望这些标签位于饼图之外,并带有指向该部分的某种箭头,或者正好位于该部分之外。
采纳答案by Alvaro Fuentes
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:
您可以使用控制从饼图中心的百分比和标签的距离pctdistance=和labeldistance=,试试这个在您的代码:
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)
您还可以使用radius=(默认为 1)设置饼图的半径

