I am interested in using RemoteGraphicsView to see if it speeds up the 
refresh rate on some sensor data I am getting and plotting as scatter plots 
( see this thread for my example program 
<https://github.com/pyqtgraph/pyqtgraph/issues/2396> ). To start, I am 
trying to just modify the RemoteSpeedTest.py file to use ScatterPlotItem's 
instead of PlotDataItem. However, it does not seem to work. My 
understanding is the .plot() method of PlotItem creates a PlotDataItem and 
renders it (with the clear keyword clearing the previous PlotDataItem). I 
naively just use the additem() method to add an explicitly created 
ScatterPlotItem. This results in a pickle error:

TypeError: cannot pickle 'ScatterPlotItem' object
How should one use RemoteGraphicsView to create a scatter plot? Also, the 
local plot doesn't event work -- I assume because the explicit clear 
deletes the ScatterPlotItem before it is rendered? Is there a better way to 
clear the plot or force it to render before the lplt.clear() call? My 
modified RemoteSpeedTest.py is below.

Thanks,

Zach


from time import perf_counter

import numpy as np

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtWidgets

app = pg.mkQApp()

view = pg.widgets.RemoteGraphicsView.RemoteGraphicsView()
pg.setConfigOptions(antialias=True)
view.pg.setConfigOptions(antialias=True)
view.setWindowTitle('pyqtgraph example: RemoteSpeedTest')

app.aboutToQuit.connect(view.close)

label = QtWidgets.QLabel()
rcheck = QtWidgets.QCheckBox('plot remote')
rcheck.setChecked(False) # It throws errors so disable.
lcheck = QtWidgets.QCheckBox('plot local')
lplt = pg.PlotWidget()
layout = pg.LayoutWidget()
layout.addWidget(rcheck)
layout.addWidget(lcheck)
layout.addWidget(label)
layout.addWidget(view, row=1, col=0, colspan=3)
layout.addWidget(lplt, row=2, col=0, colspan=3)
layout.resize(800,800)
layout.show()

rplt = view.pg.PlotItem()
rplt._setProxyOptions(deferGetattr=True)
view.setCentralItem(rplt)

lastUpdate = perf_counter()
avgFps = 0.0

def update():
    global check, label, plt, lastUpdate, avgFps, rpltfunc
    data = np.random.normal(size=(10000,50)).sum(axis=1)
    data += 5 * np.sin(np.linspace(0, 10, data.shape[0]))
    x = np.arange(len(data)) # Make explicit x data
    
    if rcheck.isChecked():
        # OLD:
        # rplt.plot(data, clear=True, _callSync='off')
        
        # rplt.plot() adds a plot item and clears, so make a ScatterPlotItem
        # and clear manually. This doesn't work.
        rplt.addItem(pg.ScatterPlotItem(x=x, y=data, _callSync='off'))
        rplt.clear()
        
    if lcheck.isChecked():
        # OLD:
        # lplt.plot(data, clear=True)
        
        # Nothing even displays here, does it clear before it renders?
        lplt.addItem(pg.ScatterPlotItem(x=x, y=data))
        lplt.clear()
        
    now = perf_counter()
    fps = 1.0 / (now - lastUpdate)
    lastUpdate = now
    avgFps = avgFps * 0.8 + fps * 0.2
    label.setText("Generating %0.2f fps" % avgFps)
        
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)

if __name__ == '__main__':
    pg.exec()

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/3dcb3d57-4677-455a-95e2-1bb2c9774c4fn%40googlegroups.com.

Reply via email to