How to plot two real-time data in one single plot in PyQtGraph?

前端 未结 1 770
野的像风
野的像风 2021-01-03 01:39

I am willing to get 2 random data and plot it in the same Widget using PyQtGraph in a real-time way. I want them to show up as Red and Blue dots. However, after a hard time,

相关标签:
1条回答
  • 2021-01-03 02:14

    While pyqtgraph is a great package from a functionality perspective, unfortunately the documentation is lacking, and you really just have to dig in to the code and start to understand the structure of the objects.

    When you call:

    p1 = win.addPlot() 
    

    This returns a reference to a PlotItem, at which point you can now add multiple PlotDataItems to this p1 object (see semi-useful structure diagram here : http://www.pyqtgraph.org/documentation/plotting.html#organization-of-plotting-classes )

    So when you call:

    curve1 = p1.plot()
    

    This adds PlotDataItem #1, ... you now need to call it again to get a second reference to use:

    curve2 = p1.plot()
    

    This becomes PlotDataItem #2, which you can then use for the 2nd setData method in your plot() method to call during update(). Which would look like:

    def plot():
    
        #Blue Dots
        curve1.setData(dataBlue, pen=None, symbol='o', symbolPen=None, symbolSize=4, symbolBrush=('b'))
        #Red Dots
        curve2.setData(dataRed, pen=None, symbol='o', symbolPen=None, symbolSize=4, symbolBrush=('r')) 
    
    0 讨论(0)
提交回复
热议问题