2013-01-10 21:10:27 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Test the speed of rapidly updating multiple plot curves
|
|
|
|
"""
|
|
|
|
|
2013-01-10 21:10:27 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
|
|
|
import initExample
|
|
|
|
|
|
|
|
|
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.ptime import time
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
|
2018-02-03 02:16:09 +00:00
|
|
|
plot = pg.plot()
|
|
|
|
plot.setWindowTitle('pyqtgraph example: MultiPlotSpeedTest')
|
|
|
|
plot.setLabel('bottom', 'Index', units='B')
|
2013-01-10 21:10:27 +00:00
|
|
|
|
2014-03-05 15:25:55 +00:00
|
|
|
nPlots = 100
|
|
|
|
nSamples = 500
|
|
|
|
curves = []
|
2018-02-03 02:16:09 +00:00
|
|
|
for idx in range(nPlots):
|
|
|
|
curve = pg.PlotCurveItem(pen=(idx,nPlots*1.3))
|
|
|
|
plot.addItem(curve)
|
|
|
|
curve.setPos(0,idx*6)
|
|
|
|
curves.append(curve)
|
2013-01-10 21:10:27 +00:00
|
|
|
|
2018-02-03 02:16:09 +00:00
|
|
|
plot.setYRange(0, nPlots*6)
|
|
|
|
plot.setXRange(0, nSamples)
|
|
|
|
plot.resize(600,900)
|
2014-03-05 15:25:55 +00:00
|
|
|
|
|
|
|
rgn = pg.LinearRegionItem([nSamples/5.,nSamples/3.])
|
2018-02-03 02:16:09 +00:00
|
|
|
plot.addItem(rgn)
|
2013-01-10 21:10:27 +00:00
|
|
|
|
|
|
|
|
2014-03-05 15:25:55 +00:00
|
|
|
data = np.random.normal(size=(nPlots*23,nSamples))
|
2013-01-10 21:10:27 +00:00
|
|
|
ptr = 0
|
|
|
|
lastTime = time()
|
|
|
|
fps = None
|
|
|
|
count = 0
|
|
|
|
def update():
|
2018-02-03 02:16:09 +00:00
|
|
|
global curve, data, ptr, plot, lastTime, fps, nPlots, count
|
2013-01-10 21:10:27 +00:00
|
|
|
count += 1
|
2018-02-03 02:16:09 +00:00
|
|
|
|
2013-01-10 21:10:27 +00:00
|
|
|
for i in range(nPlots):
|
2014-03-05 15:25:55 +00:00
|
|
|
curves[i].setData(data[(ptr+i)%data.shape[0]])
|
2018-02-03 02:16:09 +00:00
|
|
|
|
2013-01-10 21:10:27 +00:00
|
|
|
ptr += nPlots
|
|
|
|
now = time()
|
|
|
|
dt = now - lastTime
|
|
|
|
lastTime = now
|
|
|
|
if fps is None:
|
|
|
|
fps = 1.0/dt
|
|
|
|
else:
|
|
|
|
s = np.clip(dt*3., 0, 1)
|
|
|
|
fps = fps * (1-s) + (1.0/dt) * s
|
2018-02-03 02:16:09 +00:00
|
|
|
plot.setTitle('%0.2f fps' % fps)
|
2013-01-10 21:10:27 +00:00
|
|
|
#app.processEvents() ## force complete redraw for every plot
|
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.timeout.connect(update)
|
|
|
|
timer.start(0)
|
|
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode.
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|