I need to plot data generated in a loop using pyqtgraph, but every time I get the following error:
RuntimeError: wrapped C/C++ object of type PlotDataItem has been deleted
This is a minimal example that generates this error. Basically, I want to create two figures and update them with new data, as the data comes in. Does anybody know what I am doing wrong?
import random
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
class test():
def __init__(self):
self.win = pg.GraphicsWindow()
self. win.resize(800, 800)
# Create layout to hold multiple subplots
pg_layout = pg.GraphicsLayoutWidget()
# Add subplots
plot1 = pg_layout.addPlot(pen=None, symbol='x', row=0, col=0, title="Sim. vs. Ml.")
plot2 = pg_layout.addPlot(pen=None, symbol='x', row=0, col=1, title="Area")
self.p1 = plot1.plot() # create an empty "plot" (a curve to plot)
self.p2 = plot2.plot() # create an empty "plot" (a curve to plot)
# Show our layout holding multiple subplots
pg_layout.show()
def update_plot(self,data):
self.p1.setData(data)
QtGui.QApplication.processEvents()
def run(self):
while True:
x = random.sample(range(1, 100), 20)
self.update_plot(x)
t = test()
t.run()