From: Gregor T. <gre...@gm...> - 2008-05-23 11:29:57
|
Robert Garrett schrieb: > Hi, > I'd like to use Python to plot data in real-time. I've created a GUI > using wxPython and have embedded a Matplotlib graph into a pane. My > problem is that I don't know the best way to update the graph. What's > the recommended method for this? First use the set_data (or set_xdata, set_ydata) methods of the artists which you might have created with the plot command. Then redraw the figure on screen using a .canvas.draw() call of your figure object. > The data comes from a peripheral device connected to the PC, so I also > need a way of regularly polling the hardware. I've managed this using > a separate thread, but this doesn't work for updating the graph (Xlib > complained). In wxPython changing the GUI should only happen from the main thread. Use wx.PostEvent with some user defined event object to send the newly aquired data from the acquisition thread to the main thread. In the event handling routine update the graph as described above. See the threading demo of the wxPython demo how to implement this. Gregor |