import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import sys
class DataPlots(object):
def __init__(self, data, index, title, interval):
self.title = title
self.interval = interval
self.data = data
self.index = index
self.win = pg.GraphicsWindow()
self.win.setWindowTitle(self.title)
self.p = self.win.addPlot()
self.curve = self.p.plot(self.data[:self.index], pen='k')
self.timer = pg.QtCore.QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(self.interval)
def update(self):
print 'Timer for: ' + self.title
self.index += 1
self.curve.setData(self.data[:self.index])
if __name__ == '__main__':
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
pg.mkPen(1)
x = np.linspace(-np.pi, np.pi, 201) # generate angle data from -pi to pi
y1 = np.sin(x) # generate an array of sin(angle)
y2 = np.cos(x) # generate an array of cose(angle)
i = 2
myPlot1 = DataPlots(y1, i, 'FirstPlot', 1000)
myPlot2 = DataPlots(y2, i, 'SecondPlot', 1000)
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()