Hi Darren,

On Fri, May 29, 2009 at 01:50, Darren Dale <dsdal...@gmail.com> wrote:
> On Thu, May 28, 2009 at 6:01 PM, Sandro Tosi <mo...@debian.org> wrote:
>>
>> Hi Darren,
>>
>> On Thu, May 28, 2009 at 19:16, Darren Dale <dsdal...@gmail.com> wrote:
>> > Try the attached script.
>>
>> Oh it works very great! thanks you very much!
>>
>> One thing I've done is also remove
>>
>> import matplotlib
>> matplotlib.use('Qt4Agg')
>>
>> since we're already importing the qt4agg backend directly right after.
>>
>> One only thing it's left a bit obscure (also because doc is a little
>> missing) is this piece of code:
>>
>>        # 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)
>>
>> first, I've not clear wat draw_artist and blit does, so if you can
>> shine some light on me :)
>>
>> Secondly, the "effect" I'd like to achieve is to update the current
>> line values and "replace" the current line with a new one. In this
>> code, instead, the line is plotted keeping the previous instances
>> around. So the effect is to fil the canvas with sin function plots
>> instead of updating only one instance.
>>
>> Do you know how to "fix" this?
>
> Not off the top of my head. Maybe someone else on the list can offer a
> suggestion.

Thanks a lot for your help! Early morning coding did help! :)

I'm attaching a script to do what I wanted to. The solution was to
remove the animated=True when calling self.ax.plot and then call an
explicit self.fig.canvas.draw() - and here it is an animate sin and
cos function! :)

Cheers,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
# 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.sin_line, = self.ax.plot(self.x, np.sin(self.x))#, animated=True, lw=2)
        self.cos_line, = self.ax.plot(self.x, np.cos(self.x))
        
        self.fig.canvas.draw()

        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.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0))
        self.cos_line.set_ydata(np.cos(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)
        self.fig.canvas.draw()

        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

Reply via email to