implementing pyqtgraph for live data graphing

為{幸葍}努か 提交于 2019-11-28 19:58:45

You have not explained what does not work about the example posted. Are there error messages? Does the process fail to receive messages? Are the plot results somehow different from what you expect?

As an initial answer, I'll recommend a different approach: use pyqtgraph's built-in multiprocessing functionality. If you run this code from your main process, it will give you a proxy to a plot window and curve running in a new process. Any methods you call on the proxies will be forwarded to the remote process:

import pyqtgraph as pg
pg.mkQApp()

# Create remote process with a plot window
import pyqtgraph.multiprocess as mp
proc = mp.QtProcess()
rpg = proc._import('pyqtgraph')
plotwin = rpg.plot()
curve = plotwin.plot(pen='y')

# create an empty list in the remote process
data = proc.transfer([])

# Send new data to the remote process and plot it
# We use the special argument _callSync='off' because we do
# not want to wait for a return value.
data.extend([1,5,2,4,3], _callSync='off')
curve.setData(y=data, _callSync='off')

Note that all of the objects we created here--rpg, plotwin, curve, and data--are proxies for real objects in the remote process. Thus almost anything you can do with the usual pyqtgraph classes can also be done with these objects and the results will appear in the remote process. For example:

# Local code:
win = pg.GraphicsWindow()
p1 = win.addPlot()
p2 = win.addPlot()

# Remote code:
win = rpg.GraphicsWindow()
p1 = win.addPlot()
p2 = win.addPlot()

The only difference for the two examples is the starting point--pg for the local pyqtgraph module, and rpg for the remote module.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!