Hi Sandro, On Wed, May 27, 2009 at 7:14 PM, Sandro Tosi <mo...@debian.org> wrote:
> Hi Darren, > thanks for replying > > On Wed, May 27, 2009 at 21:01, Darren Dale <dsdal...@gmail.com> wrote: > > On Wed, May 27, 2009 at 9:11 AM, Sandro Tosi <mo...@debian.org> wrote: > >> > >> Hi all, > >> I'd like to adapt 'animation_blit_qt4.py' to a pure OO approach, > >> removing pylab from the code and move to something near to > >> 'embedding_in_qt4.py'. > >> > >> I tried a bit but failed miserably :( > >> > >> What I'd like to achieve is use something like in > >> 'embedding_in_qt4.py' but that can be updated using the timerEvent / > >> startTime paradigm (something similar to gobject.add_idle(func) but > >> this time for Qt4). > >> > >> Can someone please give me a help on this? > > > > Can you be more specific? Maybe post what you have along with a > description > > of how it is failing? > > Eheh, sorry for being so generic: I wrote that email from work, while > the code I've worked on was at home ;) > > So, the situation is this: > > - animation_blit_qt4.py has a nice way to update the graph "online", > using the timerEvent/startTimer > - animation_blit_qt4.py contains pylab staff (I want to avoid using) > - animation_blit_qt4.py uses the backend Qt4Agg not the backend object > - embedding_in_qt4.py uses an OO approach at embedding mpl in a qt4 > widget/application. > > The ultimate result I want to achieve is to embed mpl in a qt4 > application but update the graph in realtime. > > So I started modifying animation_blit_qt4.py to make it "more OO" :) > > The attached script "animation_blit_qt4_morph.py" only replaced the > pylab parts with a mix of OO style and pyplot, and the timerEvent just > print the receive event without updating the graph. > > As you can see, not much of what I need :( > > What I'd like to achive is something similar to > "embedding_in_qt4_morph.py" but where the graph is updated > automatically like in an animation. > > Your help will be appreciated a lot :) > Try the attached script. Darren
# For detailed comments on animation and the techniqes used here, see # the wiki entry http://www.scipy.org/Cookbook/Matplotlib/Animations import os import sys import matplotlib matplotlib.use('Qt4Agg') from matplotlib.figure import Figure from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from PyQt4 import QtCore, QtGui ITERS = 1000 import numpy as np import time class BlitQT(FigureCanvas): def __init__(self): self.fig = Figure() self.ax = self.fig.add_subplot(111) self.ax.grid() FigureCanvas.__init__(self, self.fig) self.cnt = 0 self.x = np.arange(0,2*np.pi,0.01) self.line, = self.ax.plot(self.x, np.sin(self.x), animated=True, lw=2) self.tstart = time.time() self.startTimer(10) def timerEvent(self, evt): #if self.old_size != current_size: # self.old_size = current_size # self.background = self.canvas.copy_from_bbox(self.ax.bbox) # restore the clean slate background #self.restore_region(self.background) # update the data self.line.set_ydata(np.sin(self.x+self.cnt/10.0)) # just draw the animated artist self.ax.draw_artist(self.line) # just redraw the axes rectangle self.blit(self.ax.bbox) if self.cnt==ITERS: # print the timing info and quit print 'FPS:' , ITERS/(time.time()-self.tstart) sys.exit() else: self.cnt += 1 app = QtGui.QApplication(sys.argv) widget = BlitQT() widget.show() sys.exit(app.exec_())
------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users