Commit 13b201be authored by Luke Campagnola's avatar Luke Campagnola
Browse files

ScatterPlotItem overhaul:

  - performance improvements
  - removed 'identical' argument; this is now handled automatically
  - some minor API changes to SpotItem
parent 2a6cc842
......@@ -28,19 +28,25 @@ print "Generating data, this takes a few seconds..."
## 1) All spots identical and transform-invariant (top-left plot).
## In this case we can get a huge performance boost by pre-rendering the spot
## image and just drawing that image repeatedly. (use identical=True in the constructor)
## (An even faster approach might be to use QPainter.drawPixmapFragments)
## image and just drawing that image repeatedly.
n = 300
s1 = pg.ScatterPlotItem(size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 20), identical=True)
s1 = pg.ScatterPlotItem(size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 120))
pos = np.random.normal(size=(2,n), scale=1e-5)
spots = [{'pos': pos[:,i], 'data': 1} for i in range(n)] + [{'pos': [0,0], 'data': 1}]
s1.addPoints(spots)
w1.addItem(s1)
## This plot is clickable
## Make all plots clickable
lastClicked = []
def clicked(plot, points):
global lastClicked
for p in lastClicked:
p.resetPen()
print "clicked points", points
for p in points:
p.setPen('b', width=2)
lastClicked = points
s1.sigClicked.connect(clicked)
......@@ -72,12 +78,13 @@ w3.addItem(s3)
s3.sigClicked.connect(clicked)
## Coming: use qpainter.drawpixmapfragments for scatterplots which do not require mouse interaction
## Test performance of large scatterplots
s4 = pg.ScatterPlotItem(size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 20), identical=True)
s4 = pg.ScatterPlotItem(size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 20))
pos = np.random.normal(size=(2,10000), scale=1e-9)
s4.addPoints(x=pos[0], y=pos[1])
w4.addItem(s4)
s4.sigClicked.connect(clicked)
......
......@@ -13,25 +13,23 @@ from pyqtgraph.ptime import time
app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
from ScatterPlotSpeedTestTemplate import Ui_Form
p = pg.plot()
p.setRange(QtCore.QRectF(0, -10, 5000, 20))
p.setLabel('bottom', 'Index', units='B')
win = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(win)
win.show()
#curve.setFillBrush((0, 0, 100, 100))
#curve.setFillLevel(0)
p = ui.plot
#lr = pg.LinearRegionItem([100, 4900])
#p.addItem(lr)
data = np.random.normal(size=(50,5000))
data = np.random.normal(size=(50,500), scale=100)
ptr = 0
lastTime = time()
fps = None
def update():
global curve, data, ptr, p, lastTime, fps
p.clear()
curve = pg.ScatterPlotItem(x=data[ptr%10], y=data[(ptr+1)%10], pen='w', brush='b', size=10, pxMode=True, identical=True)
curve = pg.ScatterPlotItem(x=data[ptr%10], y=data[(ptr+1)%10], pen='w', brush='b', size=10, pxMode=ui.pixelModeCheck.isChecked())
p.addItem(curve)
ptr += 1
now = time()
......
......@@ -10,10 +10,11 @@ class GraphicsItem(object):
Abstract class providing useful methods to GraphicsObject and GraphicsWidget.
(This is required because we cannot have multiple inheritance with QObject subclasses.)
"""
def __init__(self):
def __init__(self, register=True):
self._viewWidget = None
self._viewBox = None
GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items()
if register:
GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items()
def getViewWidget(self):
"""
......
......@@ -89,7 +89,7 @@ class PlotDataItem(GraphicsObject):
**Optimization keyword arguments:**
========== ================================================
identical spots are all identical. The spot image will be rendered only once and repeated for every point
identical *deprecated*
decimate (int) decimate data
========== ================================================
......
This diff is collapsed.
......@@ -52,6 +52,9 @@ class GraphicsView(QtGui.QGraphicsView):
self.setCacheMode(self.CacheBackground)
## This might help, but it's probably dangerous in the general case..
#self.setOptimizationFlag(self.DontSavePainterState, True)
if background is not None:
brush = fn.mkBrush(background)
self.setBackgroundBrush(brush)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment