473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

wxpython, updating plot (wx.lib.plot)

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
1 8304
jlm699
314 100+
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

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

Similar topics

3
by: Steve Lamb | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ok, this one I did try before coming here... :) I am trying to report the status of what is going on to the status bar of the main window of my...
10
by: Oh Kyu Yoon | last post by:
Does anyone know how to implement plots from scipy, chaco, etc into wxPython widget? Thank you
8
by: Jan Danielsson | last post by:
Hello all, I wanted to plot some statistics, so I wrote a simple wxPython class to do it. Then I realized that I would like to draw bar graphs, so I added that too. Since I'm a complete...
0
by: ajikoe | last post by:
Hello, I make a windows button which show pylab plot. When I click the button the plot is showed, then I close the plot. But the second click will always produce the plot (which can't be...
4
by: KvS | last post by:
Hi all, I'm pretty new to (wx)Python so plz. don't shoot me if I've missed something obvious ;). I have a panel inside a frame, on which a Button and a StaticText is placed: self.panel =...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Soren | last post by:
Hi, I'm trying to create a small GUI program where I can do plots using Matplotlib. I've been trying to borrow code from the examples at the matplotlib website, but I can't get it to work. I...
0
by: Soren | last post by:
Hi, I've been trying to embed matplotlib in wxpython. I want to be able to put a figure (axes) in a wx.Panel and place it somewhere in my GUI. The GUI should have other panels with buttons etc....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.