2012-04-30 22:20:27 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
For testing rapid updates of ScatterPlotItem under various conditions.
|
|
|
|
|
|
|
|
(Scatter plots are still rather slow to draw; expect about 20fps)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-30 22:20:27 +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-04-30 22:20:27 +00:00
|
|
|
|
|
|
|
|
2018-02-17 04:42:34 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore, QT_LIB
|
2012-04-30 22:20:27 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.ptime import time
|
|
|
|
#QtGui.QApplication.setGraphicsSystem('raster')
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
#mw = QtGui.QMainWindow()
|
|
|
|
#mw.resize(800,800)
|
2018-02-17 04:42:34 +00:00
|
|
|
if QT_LIB == 'PySide':
|
2012-09-09 23:07:36 +00:00
|
|
|
from ScatterPlotSpeedTestTemplate_pyside import Ui_Form
|
2018-02-17 04:42:34 +00:00
|
|
|
elif QT_LIB == 'PySide2':
|
2016-09-18 08:20:24 +00:00
|
|
|
from ScatterPlotSpeedTestTemplate_pyside2 import Ui_Form
|
2018-02-17 04:42:34 +00:00
|
|
|
elif QT_LIB == 'PyQt5':
|
2015-02-28 16:05:57 +00:00
|
|
|
from ScatterPlotSpeedTestTemplate_pyqt5 import Ui_Form
|
2012-09-09 23:07:36 +00:00
|
|
|
else:
|
|
|
|
from ScatterPlotSpeedTestTemplate_pyqt import Ui_Form
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-05-11 03:37:07 +00:00
|
|
|
win = QtGui.QWidget()
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: ScatterPlotSpeedTest')
|
2012-05-11 03:37:07 +00:00
|
|
|
ui = Ui_Form()
|
|
|
|
ui.setupUi(win)
|
|
|
|
win.show()
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-05-11 03:37:07 +00:00
|
|
|
p = ui.plot
|
2014-01-17 01:34:05 +00:00
|
|
|
p.setRange(xRange=[-500, 500], yRange=[-500, 500])
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-05-11 03:37:07 +00:00
|
|
|
data = np.random.normal(size=(50,500), scale=100)
|
2012-10-19 02:48:36 +00:00
|
|
|
sizeArray = (np.random.random(500) * 20.).astype(int)
|
2012-04-30 22:20:27 +00:00
|
|
|
ptr = 0
|
|
|
|
lastTime = time()
|
|
|
|
fps = None
|
|
|
|
def update():
|
|
|
|
global curve, data, ptr, p, lastTime, fps
|
|
|
|
p.clear()
|
2012-10-03 01:23:59 +00:00
|
|
|
if ui.randCheck.isChecked():
|
|
|
|
size = sizeArray
|
|
|
|
else:
|
|
|
|
size = ui.sizeSpin.value()
|
2014-01-17 01:34:05 +00:00
|
|
|
curve = pg.ScatterPlotItem(x=data[ptr%50], y=data[(ptr+1)%50],
|
|
|
|
pen='w', brush='b', size=size,
|
|
|
|
pxMode=ui.pixelModeCheck.isChecked())
|
2012-04-30 22:20:27 +00:00
|
|
|
p.addItem(curve)
|
|
|
|
ptr += 1
|
|
|
|
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
|
|
|
|
p.setTitle('%0.2f fps' % fps)
|
2012-10-19 02:48:36 +00:00
|
|
|
p.repaint()
|
|
|
|
#app.processEvents() ## force complete redraw for every plot
|
2012-04-30 22:20:27 +00:00
|
|
|
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_()
|