单个图中的 PyQt5 pyqtgraph (adding/removing) 曲线
PyQt5 pyqtgraph (adding/removing) curves in a single plot
我是 pyqt5 的新手,正在寻找一些方向。
在单个 pyqtgraphics PlotItem Graph 中,我想 add/remove 可配置的 PlotCurveItems。
我从 QWidgetList 项目开始,但它似乎无法让我添加具有多个配置的相同 ListItem-> 函数。
作为下一步,我正在考虑使用参数树,但不确定我是否只是让事情变得更复杂。
最后,我想使用 PlotItem.addItem() 来 运行 一个可配置的 function/method 并查看我添加的可以删除或重新配置的项目列表。
提前致谢。
您可能会在这里找到您要找的东西:
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()
我是 pyqt5 的新手,正在寻找一些方向。
在单个 pyqtgraphics PlotItem Graph 中,我想 add/remove 可配置的 PlotCurveItems。 我从 QWidgetList 项目开始,但它似乎无法让我添加具有多个配置的相同 ListItem-> 函数。
作为下一步,我正在考虑使用参数树,但不确定我是否只是让事情变得更复杂。 最后,我想使用 PlotItem.addItem() 来 运行 一个可配置的 function/method 并查看我添加的可以删除或重新配置的项目列表。
提前致谢。
您可能会在这里找到您要找的东西:
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()