By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

wxpython, updating plot (wx.lib.plot)

P: 75
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... =/

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3.  
  4. import wx
  5. import wx.lib.plot as plot
  6.  
  7. class MyFrame(wx.Frame):
  8.     def __init__(self):
  9.         self.frame1 = wx.Frame(None, title="test", id=-1, size=(500, 300))
  10.         self.panel1 = wx.Panel(self.frame1)
  11.         self.panel1.SetBackgroundColour("white")
  12.  
  13.         Button1 = wx.Button(self.panel1, -1, "Update", (200,220))
  14.         Button1.Bind(wx.EVT_BUTTON, self.redraw)
  15.  
  16.         plotter = plot.PlotCanvas(self.panel1)
  17.         plotter.SetInitialSize(size=(500, 200))
  18.  
  19.         data = [[1, 10], [2, 5], [3, 10], [4, 5]]
  20.         line = plot.PolyLine(data, colour='red', width=1)
  21.  
  22.         gc = plot.PlotGraphics([line], 'Test', 'x', 'y')
  23.         plotter.Draw(gc)
  24.  
  25.         self.frame1.Show(True)
  26.  
  27.  
  28.     def redraw(self, event):
  29.         plotter = plot.PlotCanvas(self.panel1)
  30.         plotter.SetInitialSize(size=(500, 200))
  31.  
  32.         data2 = [[1, 20], [2, 15], [3, 20], [4, -10]]
  33.         line = plot.PolyLine(data2, colour='red', width=1)
  34.  
  35.         gc = plot.PlotGraphics([line], 'Test', 'x', 'y')
  36.         plotter.Draw(gc)
  37.  
  38. app = wx.PySimpleApp()
  39. f = MyFrame()
  40. app.MainLoop()
  41.  
Jun 17 '08 #1
Share this Question
Share on Google+
1 Reply


jlm699
100+
P: 314
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
Jun 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.