Reputation: 63
I'm new to pyqt5 and am just looking for some direction.
In a single pyqtgraphics PlotItem Graph I would like to add/remove configurable PlotCurveItems. I started with QWidgetList items but it seems that will not provide me the ability to add the same ListItem->functions with multiple configurations.
As a next step I'm looking at using Parameter Trees but am not sure if I am just making things more complicated. Ultimately I would like to use the PlotItem.addItem() to run a configurable function/method and view a list of Items I have added that I can remove or reconfigure.
Thanks in advance.
Upvotes: 1
Views: 4987
Reputation: 559
You might find what you are looking for here:
import pyqtgraph.examples
pyqtgraph.examples.run()
basically you create your plot as follow:
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()
Upvotes: 1