2012-03-02 02:55:32 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Update a simple plot as rapidly as possible to measure speed.
|
|
|
|
"""
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
2012-03-02 03:53:52 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2012-03-02 02:55:32 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
2012-04-04 13:29:35 +00:00
|
|
|
from pyqtgraph.ptime import time
|
2012-03-02 02:55:32 +00:00
|
|
|
app = QtGui.QApplication([])
|
|
|
|
|
|
|
|
p = pg.plot()
|
2013-02-25 04:09:03 +00:00
|
|
|
p.setWindowTitle('pyqtgraph example: PlotSpeedTest')
|
2012-03-12 16:23:25 +00:00
|
|
|
p.setRange(QtCore.QRectF(0, -10, 5000, 20))
|
|
|
|
p.setLabel('bottom', 'Index', units='B')
|
2012-03-02 02:55:32 +00:00
|
|
|
curve = p.plot()
|
2012-04-04 13:29:35 +00:00
|
|
|
|
|
|
|
#curve.setFillBrush((0, 0, 100, 100))
|
|
|
|
#curve.setFillLevel(0)
|
|
|
|
|
|
|
|
#lr = pg.LinearRegionItem([100, 4900])
|
|
|
|
#p.addItem(lr)
|
|
|
|
|
2012-03-12 16:23:25 +00:00
|
|
|
data = np.random.normal(size=(50,5000))
|
2012-03-02 02:55:32 +00:00
|
|
|
ptr = 0
|
2012-04-04 13:29:35 +00:00
|
|
|
lastTime = time()
|
2012-03-02 02:55:32 +00:00
|
|
|
fps = None
|
|
|
|
def update():
|
|
|
|
global curve, data, ptr, p, lastTime, fps
|
|
|
|
curve.setData(data[ptr%10])
|
|
|
|
ptr += 1
|
2012-04-04 13:29:35 +00:00
|
|
|
now = time()
|
2012-03-02 02:55:32 +00:00
|
|
|
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
|
|
|
|
p.setTitle('%0.2f fps' % fps)
|
|
|
|
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.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|