【问题标题】:Manual time loop control of FuncAnimation in matplotlibmatplotlib中FuncAnimation的手动时间循环控制
【发布时间】:2014-08-06 11:50:11
【问题描述】:

我正在寻找类似于FuncAnimation 的带有 blit 的东西,但是我不想让库在固定的时间步长调用函数,而是想在我准备好时自己调用函数。我不明白 matplotlib 对函数返回的坐标轴做了什么来更新它们。我正在处理来自外部来源的实时数据,我希望刷新率与该数据同步。

【问题讨论】:

标签: python matplotlib


【解决方案1】:

我做过这样的事情

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()

【讨论】:

    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多