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
500 objects:
-100 are red
-300 are blue
-the rest are green
Is there some python package which can represent the above information
I wrote a wxPython control to render pretty 3D pie charts (see attached
piechartwindow.py). It can also be used to pre-generate images such as
this..
http://www.foodfileonline.com/static/piecharts/pie01009.jpg
Code is public domain.
Will McGugan
--
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in
"jvyy*jvyyzpthtna^pbz")
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
on a screen? in a web browser? on a printer?
</F>
-Larry Bates
> In a web browser, having a pie chart in some image format will be great.
here's a variation of jepler's tkinter example, using aggdraw to do the
drawing and PIL to generate the image. tweak as necessary.
# http://effbot.org/zone/draw-agg.htm
from aggdraw import *
# http://www.pythonware.com/products/pil/index.htm
import Image
def drawchart(size, data, range):
draw = Draw("RGB", size, "white")
bbox = 10, 10, size[0]-10, size[1]-10
for lo, hi, ink in data:
lo = 360.0 * lo / range
hi = 360.0 * hi / range
draw.pieslice(bbox, lo, hi, Brush(ink))
return Image.fromstring(draw.mode, draw.size, draw.tostring())
data = (
(0, 100, "red"),
(100, 400, "blue"),
(400, 500, "green")
)
im = drawchart((250, 250), data, 500)
im.save("chart.png")
</F>
What is the user interface context?
Is it a web page? Do you want to create image files with pie chart? If
yes to either of these, try gdchart.
http://www.icewalkers.com/Linux/Software/52020/GDChart.html
http://athani.pair.com/msteed/software/gdchart/download.html
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
I tried your script and got the following error:
Traceback (most recent call last):
File "pie_chart.py", line 302, in OnPaint
self.OnDraw()
File "pie_chart.py", line 336, in OnDraw
segment.Draw(self.angle, self.rot, self.explode)
File "pie_chart.py", line 46, in Draw
glPopMatrix()
OpenGL.GL.GLerror: [Errno 1281] invalid value
What am I doing wrong?
Regards, Markus
I'm not sure. Thats a strange place for it to fail. Do you have the
latest version of pyOpenGL / wxPython?
Its only been tested on Windows, but it just uses basic OpenGL so there
is not that much to go wrong..