implementing pyqtgraph for live data graphing

后端 未结 1 2065
走了就别回头了
走了就别回头了 2020-12-25 10:10

I am trying to get a live plot of data as it is being collected by an instrument using pyqtgraph.

The data collection is handled by the main process this is then pas

相关标签:
1条回答
  • 2020-12-25 11:05

    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.

    0 讨论(0)
提交回复
热议问题