[Tutor] passing arguments to a make a graph

Che M pine508 at hotmail.com
Fri Mar 23 19:28:00 CET 2007


Thank you, Alan.   I started by adding a method called addPoints() to my 
class as you recommend.  But now I don't know how to pass a list of points 
to the addPoints() method.  Here's the relevant code, adding in your 
suggestions:

class PlotPanel(wx.lib.plot.PlotCanvas):
    def __init__(self, points=[], *args, **kwargs):
        wx.lib.plot.PlotCanvas.__init__(self, *args, **kwargs)
        self.points = points
        self.Draw(self._drawGraph())
        self.SetEnableDrag(True)
        #self.SetEnableGrid(True)

    def addPoints(self, points):
        self.points += points

    def _drawGraph(self):
        m=[]
        m.append(wx.lib.plot.PolyLine(self.points))
        m.append(wx.lib.plot.PolyMarker(self.points))
        return wx.lib.plot.PlotGraphics(m, "Title)",
            "x axis", "")

#this button tells it to make a graph using "mypoints".

def OnGraphButton(self, event):
    mypoints = [(3,4), (5,6)]                             #these to be used 
in the plot
    PlotPanel.addPoints(PlotPanel,mypoints)
    self.notebook1.AddPage(imageId=-1, page=PlotPanel(self.notebook1), 
select=True,
              text='Weight')


The error I get using it this way is:

TypeError:  unbound method addPoints() must be called with PlotPanel 
instance as first argument (got type instance instead)

I'm lost.  Also, what does "self.points += points" mean?  What is the += 
operator?

Thanks,
Che

_________________________________________________________________
Mortgage refinance is hot 1) Rates near 30-yr lows 2) Good credit get 
intro-rate 4.625%* 
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2a5f&s=4056&p=5117&disc=y&vers=743



More information about the Tutor mailing list