[Tutor] basics of passing arguments to make a graph

Che M pine508 at hotmail.com
Fri Mar 23 02:50:31 CET 2007


Hi, this is some *really* beginner Python stuff, hope you folks could help 
me.

I've been trying to make basic plots (line graphs) using the pyplot module 
(wx.lib.plot) in wxPython.  So far, so good.  To start, I can use a class 
like this (adapted from a demo) to draw a pre-defined graph:

class PlotPanel(wx.lib.plot.PlotCanvas):
    def __init__(self, *args, **kwargs):
        wx.lib.plot.PlotCanvas.__init__(self, *args, **kwargs)     
#PlotCanvas on which I draw graph
        self.Draw(self._drawGraph())                                       
#draw it using the next function

    def _drawGraph(self):                                       #this 
function draws just this one specific graph
        points = [(1,1), (3,4), (5,7), (7,14)]             #just four points 
for a simple little line graph
        m=[]
        m.append(wx.lib.plot.PolyLine(points))                  #uses the 
points to make a line
        m.append(wx.lib.plot.PolyMarker(points))               #uses the 
points to place markers
        return wx.lib.plot.PlotGraphics(m, "Graph Title",      #return the 
whole graph with title, etc.
            "x axis", "y axis")

This makes a nice graph, but the problem is that doing it this way means I 
need a seperate class for every graph I would want to make.  Obviously not 
the way to do it.

What I want instead is a way to have a class that makes my graphs but which 
expects to be passed points from some other place, in my case, due to some 
user choice (in selecting data from a list or whatever).

I get the sense that the idea is to pass a list of points to the drawGraph 
function.  Is that right?  So far I've fooled with it but can't get it to 
work.  Mostly because I don't understand argument passing well at all (like 
the *args, **kwargs stuff is still mysterious to me).  I was hoping this 
could help touch on some good principles for how to do this type of argument 
passing generally.

Thank you,
Che

_________________________________________________________________
It’s tax season, make sure to follow these few simple tips 
http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=HMMartagline



More information about the Tutor mailing list