PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, April 23, 2022

[FIXED] How to print percentages outside the pie with python

 April 23, 2022     pie-chart, python-3.x, series     No comments   

Issue

I would like to have percentage values outside the pie. Maybe you can help

Here is my code :

import matplotlib.pyplot as plt
import pandas as pd

dict={'a':45, 'b': 123, 'c':2, 'd':1755, 'e':13}
ser = pd.Series(dict)

print(ser)

ser.plot(kind='pie', shadow=True, autopct='%1.2f%%')
plt.show()

As you can see in my case percentage values are not visible


Solution

According to the docs pctdistance controls the "ratio between the center of each pie slice and the start of the text generated by autopct", and it has a default value of 0.6, which causes the percentage values to be inside the pie.

Try a pctdistance value > 1:

>>> ser.plot(kind='pie', shadow=True, autopct='%1.2f%%', pctdistance=1.15)

(The above results in an "ugly" plot in which the percentages and the labels overlap. You can fix that by "moving" the labels using labeldistance.)



Answered By - Nikolaos Chatzis
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing