Evaluation of animated oscilloscope in gtk app and weird X error

Hi folks,

I just created a tiny prototype of an 'oscilloscope'. I get live data from a
robot via UDP. My network class calls the update() of the oscilloscope. The
oscilloscope is part of an existing GTK app which runs on an Ubuntu.

I have three questions:

1) Since it's my first animation with matplotlib I'm not sure if this is really
   the best way to do it (probably not :)). I especially dislike the creation of
   np.array which could take a bit once I have a lot of data.

2) Is the integration in a GTK app like it is now ok or is there a better way?
   I don't want to loose the zoom and move ability of the standard plot figure
   though. And I need fast results so I don't want to spent to much time
   tweaking this.

3) I get a *weird* X error when calling the update method from the network
   class which probably doesn't have to do anything with matplotlib but I'm
   asking anyway :slight_smile:

    robocup@...3096...:~/fumanoid/Desktop-Debug-YUV422$ ../install.py
    DeprecationWarning: Use the new widget gtk.Tooltip
    test from 0: 254/508
    The program 'install.py' received an X Window System error.
    This probably reflects a bug in the program.
    The error was 'RenderBadPicture (invalid Picture parameter)'.
     (Details: serial 11627 error_code 158 request_code 148 minor_code 7)
     (Note to programmers: normally, X errors are reported asynchronously;
      that is, you will receive the error a while after causing it.
      To debug your program, run it with the --sync command line
      option to change this behavior. You can then get a meaningful
      backtrace from your debugger if you break on the gdk_x_error() function.)

   Sometimes it crashes instantly, sometimes it works for a few calls.
   Calling update() from the interactive shell works fine though and displays
   everything. So I don't know if it's really X like the error message
   suggests or what. Did anybody of you experience something like this?

This is the oscilloscope:

import numpy as np
import matplotlib
#matplotlib.use('GTKAgg') # do this before importing pylab
# does not really change anything
import pylab
import matplotlib.pyplot as plt

class Oscilloscope():
    def __init__(self):
        # var for a moving window; not implemented yet
        self.NO_OF_DATA_TO_PLOT = 0

        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)

        # list of raw data
        self.raw_data_x = []
        self.raw_data_y = []

        self.graph_lim = dict(x_min=None, x_max=None,
                y_min=None, y_max=None)

        # get line of data to be able to extend it later
        self.line, = self.ax.plot(np.array(self.raw_data_x),

        # open the figure window

    def update(self, x, y):
        """Draw new data consisting of x and y."""
        print 'in update'

        # add new data
        self.line.set_xdata(np.array( self.raw_data_x))

        # redraw the canvas
        self._limit_plot(x, y)