Refactor MultiPlotSpeedTest.py
* Change variable to meaningful name, * Remove the outdated commented out code.
This commit is contained in:
parent
4ed09ebdf1
commit
81562b0252
@ -12,32 +12,27 @@ 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
|
from pyqtgraph.ptime import time
|
||||||
#QtGui.QApplication.setGraphicsSystem('raster')
|
|
||||||
app = QtGui.QApplication([])
|
app = QtGui.QApplication([])
|
||||||
#mw = QtGui.QMainWindow()
|
|
||||||
#mw.resize(800,800)
|
|
||||||
|
|
||||||
p = pg.plot()
|
plot = pg.plot()
|
||||||
p.setWindowTitle('pyqtgraph example: MultiPlotSpeedTest')
|
plot.setWindowTitle('pyqtgraph example: MultiPlotSpeedTest')
|
||||||
#p.setRange(QtCore.QRectF(0, -10, 5000, 20))
|
plot.setLabel('bottom', 'Index', units='B')
|
||||||
p.setLabel('bottom', 'Index', units='B')
|
|
||||||
|
|
||||||
nPlots = 100
|
nPlots = 100
|
||||||
nSamples = 500
|
nSamples = 500
|
||||||
#curves = [p.plot(pen=(i,nPlots*1.3)) for i in range(nPlots)]
|
|
||||||
curves = []
|
curves = []
|
||||||
for i in range(nPlots):
|
for idx in range(nPlots):
|
||||||
c = pg.PlotCurveItem(pen=(i,nPlots*1.3))
|
curve = pg.PlotCurveItem(pen=(idx,nPlots*1.3))
|
||||||
p.addItem(c)
|
plot.addItem(curve)
|
||||||
c.setPos(0,i*6)
|
curve.setPos(0,idx*6)
|
||||||
curves.append(c)
|
curves.append(curve)
|
||||||
|
|
||||||
p.setYRange(0, nPlots*6)
|
plot.setYRange(0, nPlots*6)
|
||||||
p.setXRange(0, nSamples)
|
plot.setXRange(0, nSamples)
|
||||||
p.resize(600,900)
|
plot.resize(600,900)
|
||||||
|
|
||||||
rgn = pg.LinearRegionItem([nSamples/5.,nSamples/3.])
|
rgn = pg.LinearRegionItem([nSamples/5.,nSamples/3.])
|
||||||
p.addItem(rgn)
|
plot.addItem(rgn)
|
||||||
|
|
||||||
|
|
||||||
data = np.random.normal(size=(nPlots*23,nSamples))
|
data = np.random.normal(size=(nPlots*23,nSamples))
|
||||||
@ -46,13 +41,12 @@ lastTime = time()
|
|||||||
fps = None
|
fps = None
|
||||||
count = 0
|
count = 0
|
||||||
def update():
|
def update():
|
||||||
global curve, data, ptr, p, lastTime, fps, nPlots, count
|
global curve, data, ptr, plot, lastTime, fps, nPlots, count
|
||||||
count += 1
|
count += 1
|
||||||
#print "---------", count
|
|
||||||
for i in range(nPlots):
|
for i in range(nPlots):
|
||||||
curves[i].setData(data[(ptr+i)%data.shape[0]])
|
curves[i].setData(data[(ptr+i)%data.shape[0]])
|
||||||
|
|
||||||
#print " setData done."
|
|
||||||
ptr += nPlots
|
ptr += nPlots
|
||||||
now = time()
|
now = time()
|
||||||
dt = now - lastTime
|
dt = now - lastTime
|
||||||
@ -62,13 +56,11 @@ def update():
|
|||||||
else:
|
else:
|
||||||
s = np.clip(dt*3., 0, 1)
|
s = np.clip(dt*3., 0, 1)
|
||||||
fps = fps * (1-s) + (1.0/dt) * s
|
fps = fps * (1-s) + (1.0/dt) * s
|
||||||
p.setTitle('%0.2f fps' % fps)
|
plot.setTitle('%0.2f fps' % fps)
|
||||||
#app.processEvents() ## force complete redraw for every plot
|
#app.processEvents() ## force complete redraw for every plot
|
||||||
timer = QtCore.QTimer()
|
timer = QtCore.QTimer()
|
||||||
timer.timeout.connect(update)
|
timer.timeout.connect(update)
|
||||||
timer.start(0)
|
timer.start(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Start Qt event loop unless running in interactive mode.
|
## Start Qt event loop unless running in interactive mode.
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user