wxpython, updating plot (wx.lib.plot)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dazzler
    New Member
    • Nov 2007
    • 75

    wxpython, updating plot (wx.lib.plot)

    Hi! I just moved using wxpython so I'm a quite newbie.

    I was wondering how to update plotcanvas?
    In my code I made button with event to update plotcanvas with new results, but how to properly do it? because now when I press button it makes new "layer" into my GUI and doesn't delete the old plot. Should I first delete the old one and then create new plot, or just update old one, well either way I don't know how to do it... =/

    [code="python"]
    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-

    import wx
    import wx.lib.plot as plot

    class MyFrame(wx.Fram e):
    def __init__(self):
    self.frame1 = wx.Frame(None, title="test", id=-1, size=(500, 300))
    self.panel1 = wx.Panel(self.f rame1)
    self.panel1.Set BackgroundColou r("white")

    Button1 = wx.Button(self. panel1, -1, "Update", (200,220))
    Button1.Bind(wx .EVT_BUTTON, self.redraw)

    plotter = plot.PlotCanvas (self.panel1)
    plotter.SetInit ialSize(size=(5 00, 200))

    data = [[1, 10], [2, 5], [3, 10], [4, 5]]
    line = plot.PolyLine(d ata, colour='red', width=1)

    gc = plot.PlotGraphi cs([line], 'Test', 'x', 'y')
    plotter.Draw(gc )

    self.frame1.Sho w(True)


    def redraw(self, event):
    plotter = plot.PlotCanvas (self.panel1)
    plotter.SetInit ialSize(size=(5 00, 200))

    data2 = [[1, 20], [2, 15], [3, 20], [4, -10]]
    line = plot.PolyLine(d ata2, colour='red', width=1)

    gc = plot.PlotGraphi cs([line], 'Test', 'x', 'y')
    plotter.Draw(gc )

    app = wx.PySimpleApp( )
    f = MyFrame()
    app.MainLoop()
    [/code]
  • jlm699
    Contributor
    • Jul 2007
    • 314

    #2
    plotter.Clear() should take care of clearing the canvas.

    I've only used matplotlib before; and I know that in order to get a dynamic plot up and running I had to use clear before every new plot. I assume it would be similar with wx.lib.plot

    Comment

    Working...