Creating Dynamic Graphs.

Hi, I just discovered the matplotlib.matlab

    > libraries. I am trying to create a dynamic graph using
    > this library. So far I am only able to create a static
    > view of the grap. Is is possible to create a graph that
    > is dynamic? (Example: in windows if you select task
    > manager you get a graph that shows you dynamic
    > information about the CPU and Memory Usage history.) I
    > just want to repaint the graph rather than closing it
    > and re-showing it.

Yes, this is possible. The two key ingredients are 1) the use of the
gtk.timeout_add function which will repeatedly call a function of your
choice and 2) call the relevant axis/line/patch methods to update your
figure.

Here is an example, that resets the x and y data of the plot every
1000 milliseconds

    import pygtk
    pygtk.require('2.0')
    import gtk

    from matplotlib.matlab import *

    fig = figure(1)
    ind = arange(30)
    X = rand(len(ind),10)
    lines = plot(X[:,0], 'o')

    def updatefig(*args):
        lines[0].set_data(ind, X[:,updatefig.count])
        fig.draw()
        updatefig.count += 1
        if updatefig.count<10: return gtk.TRUE
        else: return gtk.FALSE

    updatefig.count = 0

    gtk.timeout_add(1000, updatefig)
    show()

The timeout_add function will only keep calling your method as long as
you return gtk.TRUE. So in the example above, I return False after
the 10 columns of my random matrix X are plotted.

You can control other attributes of the line in a similar way, eg, by
calling set_color, set_linewidth, etc....

If you want to use technique with bar, hist, or scatter (which return
Patch instances), you'll have to wait a few minutes while I update the
code, because I haven't added a set data method for those classes.

John Hunter