Provide a different plot test

This commit is contained in:
Dennis Goeries 2021-02-11 23:14:02 +01:00 committed by Ogi Moore
parent ddf73c2ecf
commit cdb427ff2f

View File

@ -3,15 +3,14 @@
""" """
Update a simple plot as rapidly as possible to measure speed. Update a simple plot as rapidly as possible to measure speed.
""" """
## Add path to library (just for examples; you do not need this)
import initExample import initExample
## Add path to library (just for examples; you do not need this)
from time import perf_counter
from collections import deque
from pyqtgraph.Qt import QtGui, QtCore from pyqtgraph.Qt import QtGui, QtCore
import numpy as np import numpy as np
import pyqtgraph as pg import pyqtgraph as pg
from pyqtgraph.ptime import time
app = pg.mkQApp("Plot Speed Test") app = pg.mkQApp("Plot Speed Test")
p = pg.plot() p = pg.plot()
@ -20,30 +19,29 @@ p.setRange(QtCore.QRectF(0, -10, 5000, 20))
p.setLabel('bottom', 'Index', units='B') p.setLabel('bottom', 'Index', units='B')
curve = p.plot() curve = p.plot()
#curve.setFillBrush((0, 0, 100, 100))
#curve.setFillLevel(0)
#lr = pg.LinearRegionItem([100, 4900])
#p.addItem(lr)
data = np.random.normal(size=(50, 5000)) data = np.random.normal(size=(50, 5000))
ptr = 0 ptr = 0
lastTime = time() rollingAverageSize = 1000
fps = None
elapsed = deque(maxlen=rollingAverageSize)
def update(): def update():
global curve, data, ptr, p, lastTime, fps global curve, data, ptr, elapsed, ptr
curve.setData(data[ptr%10])
ptr += 1 ptr += 1
now = time() # Measure
dt = now - lastTime t_start = perf_counter()
lastTime = now curve.setData(data[ptr % 10])
if fps is None: app.processEvents(QtCore.QEventLoop.ProcessEventsFlag.AllEvents)
fps = 1.0/dt elapsed.append(perf_counter() - t_start)
else:
s = np.clip(dt*3., 0, 1) # update display every 50-updates
fps = fps * (1-s) + (1.0/dt) * s if ptr % 50 == 0:
p.setTitle('%0.2f fps' % fps) average = np.mean(elapsed)
app.processEvents() ## force complete redraw for every plot fps = 1 / average
p.setTitle('%0.2f fps - %0.1f ms avg' % (fps, average * 1_000))
timer = QtCore.QTimer() timer = QtCore.QTimer()
timer.timeout.connect(update) timer.timeout.connect(update)
timer.start(0) timer.start(0)