Creating Pie Chart from Python

T

Thierry Lam

Let's say I have the following data:

500 objects:
-100 are red
-300 are blue
-the rest are green

Is there some python package which can represen the above information
in a pie chart?

Thanks
Thierry
 
J

jepler

There are many.

One choice would be Tkinter's Canvas.

def frac(n): return 360. * n / 500

import Tkinter
c = Tkinter.Canvas(width=100, height=100); c.pack()
c.create_arc((2,2,98,98), fill="red", start=frac(0), extent = frac(100))
c.create_arc((2,2,98,98), fill="blue", start=frac(100), extent = frac(400))
c.create_arc((2,2,98,98), fill="green", start=frac(400), extent = frac(100))
c.mainloop()

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFDKZK8Jd01MZaTXX0RAuxuAJ9F9jktcSCB3fnQMCUG/9B2Ai+gHwCfbVEx
AACjDeSJO/6rj6BCBmirCKo=
=QXkW
-----END PGP SIGNATURE-----
 
K

Ken Seehart

J

John Hunter

Thierry> Let's say I have the following data: 500 objects: -100
Thierry> are red -300 are blue -the rest are green

Thierry> Is there some python package which can represen the above
Thierry> information in a pie chart?


It looks like in python there is more than one way to make a pie
chart. Here's another

from pylab import figure, pie, show
N, red, blue = 500, 100, 300
green = N - (red + blue)
figure(figsize=(6,6))
pie( (red, blue, green),
labels=('red', 'blue', 'green'),
colors=('red', 'blue', 'green'),)
show()

A screenshot of a slightly more elaborate example is at

http://matplotlib.sourceforge.net/screenshots.html#pie_demo

JDH
 
T

Thierry Lam

Those python pie chart add ons are not very useful. For my specific pie
chart, I have some 6-8 items to show up and some of them occupy only
2-5% of the pie. This cause the names and percentages to overlap each
other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,320
Members
48,004
Latest member
KelseyFors

Latest Threads

Top