Differences between revisions 2 and 3
Revision 2 as of 2005-03-17 08:26:30
Size: 222
Editor: dsl-084-056-108-058
Comment: Address of site changed.
Revision 3 as of 2006-02-10 04:50:38
Size: 1103
Editor: ool-43564de5
Comment: JohnMG
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Here's a quick example for using PyChart in a CGI script to dynamically create and return a plot in png format. Just drop it into your cgi-bin directory and point your browser at it. Please see the official PyChart docs for plenty of nicely-commented examples.
{{{#!python
#!/usr/bin/python

import random
import sys
from pychart import *

print "Content-type: image/png"
print

sys.argv.append( '--format=png' )

theme.get_options()
theme.scale_factor = 2
theme.reinitialize()

data = []
for i in range(10):
    data.append( (i, random.random()* 3.0) )

xaxis = axis.X( format="/hL%d", label="time" )
yaxis = axis.Y( label="synaptic activity" )

ar = area.T( x_axis=xaxis, y_axis=yaxis, y_range=(0,None), size=(120,110) )
plot = line_plot.T( label="cortex data", data=data, ycol=1, tick_mark=tick_mark.square )
ar.add_plot( plot )

ar.draw()
}}}

PyChart is a Python library for creating high quality Encapsulated Postscript, PDF, PNG, or SVG charts. It currently supports line plots, bar plots, range-fill plots, and pie charts.

Here's a quick example for using PyChart in a CGI script to dynamically create and return a plot in png format. Just drop it into your cgi-bin directory and point your browser at it. Please see the official PyChart docs for plenty of nicely-commented examples.

   1 #!/usr/bin/python
   2 
   3 import random
   4 import sys
   5 from pychart import *
   6 
   7 print "Content-type: image/png"
   8 print
   9 
  10 sys.argv.append( '--format=png' )
  11 
  12 theme.get_options()
  13 theme.scale_factor = 2
  14 theme.reinitialize()
  15 
  16 data = []
  17 for i in range(10):
  18     data.append( (i, random.random()* 3.0) )
  19 
  20 xaxis = axis.X( format="/hL%d",  label="time" )
  21 yaxis = axis.Y(  label="synaptic activity" )
  22 
  23 ar = area.T( x_axis=xaxis, y_axis=yaxis, y_range=(0,None), size=(120,110) )
  24 plot = line_plot.T( label="cortex data", data=data, ycol=1, tick_mark=tick_mark.square )
  25 ar.add_plot( plot )
  26 
  27 ar.draw()

http://home.gna.org/pychart/ (new)

PyChart (last edited 2008-11-15 14:00:32 by localhost)

Unable to edit the page? See the FrontPage for instructions.