Revision 3 as of 2006-02-10 04:50:38

Clear message

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)

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