animation - python Matplotlib gtk - animate plot with FuncAnimation -


i trying update plot within gtk window funkanimation. want click button start updating plot gets data txt file. txt-file gets updated constantly. intent plot temperature profile. here simplified code:

import gtk matplotlib.backends.backend_gtkagg import figurecanvasgtkagg figurecanvas import matplotlib.animation animation matplotlib import pyplot plt  class myprogram():     def __init__(self):         some_gtk_stuff         self.signals = {                 'on_button_clicked': self.create_plot,         }         self.builder.connect_signals(self.signals)          self.vbox = self.builder.get_object('vbox')          self.figure = plt.figure()         self.axis = self.figure.add_subplot(1,1,1)         self.init = 0      def create_plot(self):                                 def update_plot(i):             #read sampledata txt file             x = []             y = []             readfile = open('sampledata.txt', 'r')             sepfile = readfile.read().split('\n')             readfile.close()              data in sepfile:                 xy = data.split(',')                 x.append(int(x)                 y.append(int(y)              self.axis.plot(x, y)              if (self.init == 0):                 self.canvas = figurecanvas(self.figure)                 self.vbox.pack_start(self.canvas)                 self.canvas.show()              ani = animation.funcanimation(self.figure, update_plot, interval = 1000)             self.canvas.draw()             return ani  myprogram() gtk.main() 

so guess, problem is, create_plot function called once. plot window created in gui, doesn't updated. couldn't find solution problem. adding `return any' suggested here didn't work.

you can see working example here, code @ bottom of page.

i'm aware have implement threading logging , updating @ later time, don't work without.

any tips? :)

i think want achieve. note changed way read file. with open() f: takes care of file closing operation forgot. possible write name of signal handler in builder file 1 can self.builder.connect(self) , omit self.signals dicitonary.

import gtk matplotlib.backends.backend_gtkagg import figurecanvasgtkagg figurecanvas import matplotlib.animation animation matplotlib import pyplot plt  class myprogram():     def __init__(self):         #some_gtk_stuff         self.signals = {                 'on_button_clicked': self.create_plot,         }         self.builder.connect_signals(self.signals)          self.vbox = self.builder.get_object('vbox')          self.figure = plt.figure()         self.axis = self.figure.add_subplot(1,1,1)         self.canvas = none      def create_plot(self, button):         self.ani = animation.funcanimation(self.figure, self.update_plot, interval = 1000)       def update_plot(self, i):         #read sampledata txt file         x = []         y = []         open('sampledata.txt') f:             x_raw, y_raw = f.readline().strip().split(',')             x.append(int(x_raw))             y.append(int(y_raw))          self.axis.plot(x, y)          if not self.canvas:             self.canvas = figurecanvas(self.figure)             self.vbox.pack_start(self.canvas)             self.canvas.show()          self.canvas.draw()  myprogram() gtk.main() 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -