Hello,
I am trying to improve the performance (plotting speed) of the following
code which draws a collection of lines using QGraphicsPathItem, then
updates with new data. It is a combination of examples I have found. Is
there a way to improve this performance with RemoteGraphicsView or
MultiProcess?
My attempts have resulted in various errors but primarily of the sort:
'RuntimeError: Internal C++ object (PySide.QtGui.QGraphicsPathItem) already
deleted.'
Thank you.
# -------------------------------
import pyqtgraph as pg
import numpy as np
app = pg.mkQApp()
y = np.random.normal(size=(120,20000), scale=0.2) +
np.arange(120)[:,np.newaxis]
x = np.empty((120,20000))
x[:] = np.arange(20000)[np.newaxis,:]
view = pg.GraphicsLayoutWidget()
view.show()
w1 = view.addPlot()
class MultiLine(pg.QtGui.QGraphicsPathItem):
def __init__(self, x, y):
"""x and y are 2D arrays of shape (Nplots, Nsamples)"""
connect = np.ones(x.shape, dtype=bool)
connect[:,-1] = 0 # don't draw the segment between each trace
self.path = pg.arrayToQPath(x.flatten(), y.flatten(),
connect.flatten())
pg.QtGui.QGraphicsPathItem.__init__(self, self.path)
self.setPen(pg.mkPen('w'))
def shape(self): # override because QGraphicsPathItem.shape is too
expensive.
return pg.QtGui.QGraphicsItem.shape(self)
def boundingRect(self):
return self.path.boundingRect()
now = pg.ptime.time()
lines = MultiLine(x, y)
w1.addItem(lines)
print("Plot time: %0.2f sec" % (pg.ptime.time()-now))
# --- added ----
for i in range(10):
print(i)
y = np.random.normal(size=(120,20000), scale=0.2) +
np.arange(120)[:,np.newaxis]
x = np.empty((120,20000))
x[:] = np.arange(20000)[np.newaxis,:]
newLines = MultiLine(x, y)
# w1.addItem(newLines)
lines.setPath(newLines.path)
app.processEvents()
app.exec_()
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/bf7412ba-2962-4848-833e-08f9e6c96cce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.