import numpy as np
import pyqtgraph as pg
from pyqtgraph.widgets.RemoteGraphicsView import RemoteGraphicsView
from PyQt4 import QtCore, QtGui
pg.GraphicsLayout
p = pg.mkPen
avgFps = 0.0
lastUpdate = pg.ptime.time()
timer = QtCore.QTimer()
class SpecWidget(RemoteGraphicsView):
"""
Widget whic uses pyqtgraph to plot both spectra, the relative errors and
the signal.
"""
def __init__(self, parent=None):
super(SpecWidget, self).__init__(parent, debug=False)
glw = self.pg.GraphicsLayout()
self.glw = glw
gpen = {'color': "g", 'width': 3}
rpen = {'color': "r", 'width': 3}
self.spectrum = glw.addPlot()
self.setCentralItem(glw)
self.probe = self.spectrum.plot(pen=gpen)
self.ref = self.spectrum.plot(pen=rpen)
glw.nextRow()
self.err = glw.addPlot()
self.probe_err = self.err.plot(pen=gpen)
self.ref_err = self.err.plot(pen=rpen)
glw.nextRow()
self.signal = glw.addPlot()
self.sig = self.signal.plot(pen=gpen)
self.sig_m = self.signal.plot(pen=rpen)
self.lastUpdate = pg.ptime.time()
timer.timeout.connect(self.update_data)
def update_data(self):
x = np.arange(400)
self.probe.setData(x, np.random.randn(400), _callSync='off')
self.ref.setData(x, np.random.randn(400), _callSync='off')
self.probe_err.setData(x, np.random.randn(400), _callSync='off')
self.ref_err.setData(x, np.random.randn(400), _callSync='off')
self.sig.setData(x, np.random.randn(400), _callSync='off')
self.sig_m.setData(x, np.random.randn(400), _callSync='off')
global avgFps
global lastUpdate
now = pg.ptime.time()
fps = 1.0 / (now - lastUpdate)
lastUpdate = now
avgFps = avgFps * 0.8 + fps * 0.2
print "Generating %0.2f fps" % avgFps
i get quite abysmal performance for a 3-plot widget, each with 2 line plots, each 400-points.
Setting the line width to 1 gives an at reasonable performance, but still not very fast.
Am i doing something wrong or is it the Qt graphics system at fault?
[snip]
class SpecWidget(RemoteGraphicsView):
def update_data(self):x = np.arange(400)
self.probe.setData(x, np.random.randn(400), _callSync='off')