• 8
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

matplotlib percent label position in pie chart

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.

      • 1
    • I've never used plt.pie, but you should be able to do what you want manually. the function returns tuple (patches, texts, autotexts). autotexts is the sequence of Text containing the percentages. If you loop over them you should be able to find the 0.1% (or whatever you want) and move the position of the text (to do this decently you might need to convert to/from circular coordinates).

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)

  • 54
Reply Report

Trending Tags