Manual control of the FuncAnimation timeline in matplotlib

I am looking for something similar to FuncAnimation with blit, but instead of having the library call the function with a fixed time interval, I want me to call the function myself when I was ready. I do not understand what matplotlib does with the axes returned by the function to update them. I work with live data coming from external sources, and I want the refresh rate to be synchronized with this data.

+4
source share
1 answer

I did something like this

import sys
import os
import random
from PySide import QtGui,QtCore
os.environ['QT_API'] = 'pyside'
from matplotlib import use
use('Qt4Agg')
import pylab as plt

class Example(QtGui.QMainWindow):

    def __init__(self):
        super(Example, self).__init__()
        self.setWindowTitle('Widgets')
        self.setGeometry(300, 300, 250, 150)

        self.wid = QtGui.QWidget()
        self.grid = QtGui.QGridLayout()
        self.wid.setLayout(self.grid)
        self.setCentralWidget(self.wid)

        self.dat = []
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.toc)
        self.timer.start(100)
        self.show()

        self.fig = plt.figure(13)
        plt.show()


    def toc(self):
        val = random.uniform(-1.7, 0.78)
        self.dat.append(val)
        plt.ion()
        fig = plt.figure(13)
        plt.clf()
        plt.plot(self.dat)
        plt.ioff()

def main():
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
0
source

Source: https://habr.com/ru/post/1544774/


All Articles