【问题标题】:PyQt5 pyqtgraph (adding/removing) curves in a single plotPyQt5 pyqtgraph(添加/删除)曲线在单个图中
【发布时间】:2019-07-15 04:04:27
【问题描述】:

我是 pyqt5 的新手,正在寻找一些方向。

在单个 pyqtgraphics PlotItem 图表中,我想添加/删除可配置的 PlotCurveItems。 我从 QWidgetList 项目开始,但它似乎无法让我添加具有多个配置的相同 ListItem->函数。

下一步,我正在考虑使用参数树,但不确定我是否只是让事情变得更复杂。 最终我想使用 PlotItem.addItem() 来运行一个可配置的函数/方法并查看我添加的可以删除或重新配置的项目列表。

提前致谢。

【问题讨论】:

    标签: pyqt5 pyqtgraph


    【解决方案1】:

    您可能会在这里找到您想要的东西:

    import pyqtgraph.examples
    pyqtgraph.examples.run()
    

    基本上你创建你的情节如下:

    from PyQt5.QtGui import* 
    from PyQt5.QtCore import*
    import pyqtgraph as pg
    import numpy as np
    import sys
    
    class MyWidget(QWidget):
        def __init__(self, parent=None):
            super(MyWidget, self).__init__(parent)
            self.win = pg.GraphicsWindow()
            self.p = []
            self.c = []
            for i in range(3):
                self.p.append(self.win.addPlot(row=i, col=0))
                for j in range(2):
                    self.c.append(self.p[-1].plot(np.random.rand(100), pen=3*i+j))
            self.update()
            self.del_curve()
            self.add_curve()
    
        def update(self): # update a curve
            self.c[3].setData(np.random.rand(100)*10)
    
        def del_curve(self): # remove a curve
            self.c[5].clear()
    
        def add_curve(self): # add a curve
            self.c.append(self.p[2].plot(np.random.rand(100)))
    
    def startWindow():
        app = QApplication(sys.argv)
        mw = MyWidget()
        app.exec_()
    
    if __name__ == '__main__':
        startWindow()
    

    【讨论】:

    • 谢谢。设置了曲线变量后,您如何能够仅删除该变量?只使用标准del variable?这就是我在 PlotItem 类下使用 addItem()/removeItem() 的原因。
    • [curve].clear() 只是清除行显示,图例仍然显示该行的数据,您需要调用 removeItem() 完全删除行数据
    猜你喜欢
    • 2020-07-03
    • 2018-10-08
    • 1970-01-01
    • 2013-05-17
    • 2015-10-26
    • 2019-04-16
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    相关资源
    最近更新 更多