Graph animation performance

Hello,
I want a real-time animation. There is no loop in the animation because
the data comes from the real world (AD data). I wrote this class:

class Eigendiagramm(object):
    def __init__(self,daten):
        self.DiagrammBreite = gtk.Adjustment(100,20,10000,1,10,10)
        self.DiagrammBreiteWidget = gtk.VScale(self.DiagrammBreite)
        self.DiagrammBreiteWidget.connect("value_changed",
self.updateBreite, None)
       
        self.data = daten
       
        self.fig = Figure()

        self.fig.set_animated(True)
        self.graph = self.fig.add_subplot(111)
        self.line, = self.graph.plot(self.data.get_ekg_data(),)
        self.graph.axis([0, self.DiagrammBreite.get_value(), 0, 4096])
        self.canvas = FigureCanvas(self.fig)

        self.DiagrammBreite = gtk.Adjustment(100,20,10000,1,10,10)
        self.DiagrammBreiteWidget = gtk.VScale(self.DiagrammBreite)
        self.DiagrammBreiteWidget.connect("value_changed",
self.updateBreite, None)
            
    def updateGraph(self,data):
        datacut = data[10000 - self.DiagrammBreite.get_value():10000]
        self.line.set_ydata(datacut)
        self.line.set_xdata(numpy.arange(0, datacut.size, 1))
        self.fig.canvas.draw()

    def updateBreite(self,widget, data = None):
        self.graph.axis([0, self.DiagrammBreite.get_value(), 0, 4096])

It works but it is very slow. (About 160mS for updateGraph when I have
two graphs) Is there any possibility to improve the performance? I
embedded the figure in GTK.

I looked to animation examples but every example there is a loop. So I
don't know how to use this class for my problem.

Peter

    def updateGraph(self,data):
        datacut = data[10000 - self.DiagrammBreite.get_value():10000]
        self.line.set_ydata(datacut)
        self.line.set_xdata(numpy.arange(0, datacut.size, 1))
        self.fig.canvas.draw()

If nothing else, it appears that the plot's x data are constant. Have
you tried just setting it once when you create self.line?

Skip

Hello,
I set the x data only once now. It is a little bit faster (about 10%).
I'm still looking for a solution which only redraws the line and not the
whole widget.
Peter

···

Am 25.08.2013 15:00, schrieb Skip Montanaro:

    def updateGraph(self,data):
        datacut = data[10000 - self.DiagrammBreite.get_value():10000]
        self.line.set_ydata(datacut)
        self.line.set_xdata(numpy.arange(0, datacut.size, 1))
        self.fig.canvas.draw()

If nothing else, it appears that the plot's x data are constant. Have
you tried just setting it once when you create self.line?

Skip