Hi PyX Users,

I very much appreciate your help posting your examples and advise to
the "PyX-user" mail list!

I have almost finished my Python-PyX based module that graphs the data
with timestamps from MySQL database.

I must give the credit to Simon Bruderer, a very bright physics PhD
student at the Zürich University
(http://n.ethz.ch/~simonbr/mathinfo_programme_pyxexamples.html).

His examples are so comprehensive (especially if you know German ;-)
and well developed. Well done!

Here is my example:

# ----------------Example file begin-------------------#

import sys
import os

sys.path.insert( 0, "/opt/PyX-module" )
from pyx import *
#from pyx.graph.axis import painter, tick
#text.set(fontmaps="psfonts.cmz")

#c=canvas.canvas()

#c.text(7,14.5,"Named Values Example",
#       [text.halign.center, text.valign.bottom, text.size.Large])

mypainter=graph.axis.painter.bar(
          nameattrs=[trafo.rotate(90),text.halign.right,text.size.Large])

g=graph.graphxy(width=15,height=15,
                  x=graph.axis.bar( painter = mypainter )
#                 y=graph.axis.log( min=1.0e-4,max=1.0,title="Values" )
)

# Connect to MySQL Database

#my_db_con = MySQLdb.Connect( host = '192.168.xxx.xxx', user = 'user',
passwd = 'password', db = 'db_name' )
#my_db_cursor = my_db_con.cursor()
#my_db_cursor.execute( "select date_and_time, data_value from my_table" )
#query_results = my_db_cursor.fetchall()

# The problem I also need to resolve is the multiple values with the
same timestamp

#data = get_min_max_average( query_results )

# Data in the tupple form in format ( "datetime", some_average,
min_value, max_value )
data=( ( "12/12/2008-12:33:45" ,0.25, 0.1, 0.6 ),
       ( "01/01/2009-09:29:43" ,0.08, 0.06, 0.1 ),
       ( "05/01/2009-11:36:11" ,0.45, 0.4, 0.5 ),
       ( "20/01/2009-00:34:55" ,1.55, 1.4, 1.7 ),
       ( "17/02/2009-22:11:00" ,0.1, 0.1, 0.1 )
     )          
                                        
g.plot([graph.data.points(data,xname=1,y=2,ymin=3,ymax=4,stack=2)],
       [graph.style.stackedbarpos("stack"),
        
graph.style.bar(barattrs=[color.rgb.white,deco.stroked([color.grey.white])]),
        graph.style.symbol(symbolattrs=[color.rgb.green]),
        graph.style.errorbar(errorbarattrs=[color.rgb.red])])

# The text for the example is build within the Graph
# using it's top as a reference point and building upwards.
# TODO: Build this in a A4 or Letter standard printing format
#       using Canvas object with the size of the sheet.
g.text( g.width/2.0, g.height+0.5, "Graph header for the Named Values Example",
       [text.halign.center, text.valign.bottom, text.size.Large] )

g.text( 0, g.height+2.0 , "to \"some average\", \"min\" and \"max\" values.",
       [text.halign.left, text.valign.bottom, text.size.Large] )

g.text( 0, g.height+2.5 , "A function converts the multiple values for
the timestamp",
       [text.halign.left, text.valign.bottom, text.size.Large] )

g.text( 0, g.height+3.0 , "Data could have many values with the same
timestamp!!!",
       [text.halign.left, text.valign.bottom, text.size.Large] )

g.text( g.width/2.0, g.height+4.0 , "Named Values Example:",
       [text.halign.center, text.valign.bottom, text.size.Large] )

filename="plot_named_values"
g.writeEPSfile(filename)
g.writePDFfile(filename)

# ----------------Example file end-------------------#

You need the latest source from the Subversion repository installed
(as instructed) for my case at /opt/PyX-module.

Please let me know if you need any help.

Kind regards,

Alex

P.S. I really look forward for news from the timeaxis, when it starts
to handle time as well. Please, keep me posted!

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to