? RE Dynamically updating embedding figures in GTK

I am trying to dynamically update some figures that I

    > have embedded in GTK. The figures display fine and if I
    > minimize and then maximize the window the figures update
    > but I can't get the figures to update dynamically as you
    > watch the window. To try and get this working I used the
    > code from one of the dynamic samples and just embedded it
    > in my application.

Hi Melissa,

You were using kind of a hybrid of what I call the matlab interface
and the application interface, so I rewrote your example in the way I
would do it if I were embedding the dynamic demo in a GTK
application. The code is for the latest release (0.54) where some of
the API changed as discussed in the release notes, and would be
slightly different for earlier versions of matplotlib.

The major difference is that under the new API, you create axes and
subplots from a Figure instance with, for example,

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

Hope this helps,

import pygtk
import gtk
import time
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.matlab import *

class C:
    def __init__(self):
        self.figure = Figure( figsize=(8,6), dpi=72)
        self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea

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

        self.win = gtk.Window()
        self.win.set_name("Embedding in GTK")
        self.win.connect("destroy", gtk.mainquit)


    def create_AntennaResponseDisplay (self, title):

        ind = arange(1,9)
        p1,p2,p3,p4,p5,p6,p7,p8 = self.ax.bar(ind, self.get_stats())
        centers = ind + 0.5*p1.get_width()

        self.ax.set_xticklabels(['1', '2', '3', '4', '5', '6', '7', '8'])
        t = self.figure.text(0.5, 0.95, title,
            horizontalalignment = 'center', fontsize = 10,)

        def updatefig(*args):
            e1, e2, e3, e4, e5, e6, e7, e8 = self.get_stats()



            return gtk.TRUE

        gtk.timeout_add(250, updatefig)
    def get_memory(self):
        "Simulate a function that returns system memory"
        return 100*(0.5+0.5*sin(0.5*pi*time.time()))

    def get_cpu(self):
        "Simulate a function that returns cpu usage"
        return 100*(0.5+0.5*sin(0.2*pi*(time.time()-0.25)))

    def get_net(self):
        "Simulate a function that returns network bandwidth"
        return 100*(0.5+0.5*sin(0.7*pi*(time.time()-0.1)))

    def get_stats(self):
        return self.get_memory(), self.get_cpu(), self.get_net(), \
               self.get_memory(), self.get_cpu(), self.get_net(), \
               self.get_memory(), self.get_cpu()

c = C()