John Hunter wrote:
> Use the gtk mainloop and do your figure updates in a timeout add or a
> idle handler (as suggested in the animation tutorial at
> http://www.scipy.org/Cookbook/Matplotlib/Animations

Excellent, thanks. Your sample code adapted nicely; appended below for 
posterity.


dan



import gobject
import numpy as np
import matplotlib
matplotlib.use('GTKAgg')
import matplotlib.pyplot as plt
import threading, time

class PylabThread(threading.Thread):
   def __init__(self):
     threading.Thread.__init__(self)
     self.fig = plt.figure()
     ax = self.fig.add_subplot(111)
     self.line, = ax.plot(np.random.rand(10))
     ax.set_ylim(0, 1)
   def update(self):
     self.line.set_ydata(np.random.rand(10))
     self.fig.canvas.draw_idle()
     return True  # return False to terminate the updates
   def run(self):
     gobject.timeout_add(100, self.update)  # you can also use idle_add 
to update when gtk is idle
     plt.show()


if __name__ == "__main__":
   p = PylabThread()
   p.start()

   i = 0
   while True:
     print "%.2f: %d" % (time.time(), i)
     i += 1
     time.sleep(.5)

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to