I want to build an interface with certain real-time graphs showing the results of some experiments. For this, I decided to use a combination of glade(UI), gtk, python, and matplotlib. I was working with some basics and I was able to plot some real-time graphs.
Now, I have some trouble using Funcanimation for real-time animations. Below, the code import a glade file with four scrolled windows and I want to display some animation in each scrolled windows. I tired the animation without plotting inside the canvas (inside the scrolled window) and it works!. But when I tried to run this, the callback function by Funcanimation (update_line) is not even triggering. What is actually I'm doing wrong here. I am new to python as well.
Thanks
#!/usr/bin/env python
import sys
import os
import time
import psutil as p
import threading
import numpy as np
from gi.repository import Gtk
from gi.repository import GObject
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
import matplotlib.pyplot as plt
class windowSignals:
def on_mainWindow_destroy(self, widget):
Gtk.main_quit()
def main():
builder = Gtk.Builder()
builder.add_from_file("window.glade")
builder.connect_signals(windowSignals())
window = builder.get_object("mainWindow")
sw = builder.get_object("scrolledWindow1")
def update_line(num, data, line):
data.pop(0)
data.append(np.random.random())
line.set_ydata(data)
return line,
fig1 = plt.figure()
data = [0.0 for i in xrange(100)]
l, = plt.plot(data, 'r-')
plt.ylim(-1, 1)
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l), interval=50, blit=True)
can = FigureCanvas(fig1)
sw.add_with_viewport(can)
can.draw()
window.show_all()
Gtk.main()
if __name__ == "__main__":
main()