From f7364f52b3218a3ea85d3d6ad179ec28e600b11b Mon Sep 17 00:00:00 2001 From: Daniel Hrisca Date: Mon, 4 May 2020 23:42:03 +0300 Subject: [PATCH] improve SymbolAtlas.getSymbolCoords performance (#1184) * remote legacy work-around for old numpy errors * forgot to remove the numpy_fix import * require numyp >= 1.8.0 * improve performance of updateData PlotCurveItem (saves about 2us per call) * improve ScatterPlotItem performance --- pyqtgraph/graphicsItems/ScatterPlotItem.py | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index aa2cabba..a774a30f 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -122,26 +122,35 @@ class SymbolAtlas(object): """ Given a list of spot records, return an object representing the coordinates of that symbol within the atlas """ - sourceRect = np.empty(len(opts), dtype=object) + + sourceRect = [] keyi = None sourceRecti = None - for i, rec in enumerate(opts): - key = (id(rec[3]), rec[2], id(rec[4]), id(rec[5])) # TODO: use string indexes? + symbol_map = self.symbolMap + + for i, rec in enumerate(opts.tolist()): + size, symbol, pen, brush = rec[2: 6] + + key = id(symbol), size, id(pen), id(brush) if key == keyi: - sourceRect[i] = sourceRecti + sourceRect.append(sourceRecti) else: try: - sourceRect[i] = self.symbolMap[key] + sourceRect.append(symbol_map[key]) except KeyError: newRectSrc = QtCore.QRectF() - newRectSrc.pen = rec['pen'] - newRectSrc.brush = rec['brush'] - newRectSrc.symbol = rec[3] - self.symbolMap[key] = newRectSrc + newRectSrc.pen = pen + newRectSrc.brush = brush + newRectSrc.symbol = symbol + + symbol_map[key] = newRectSrc self.atlasValid = False - sourceRect[i] = newRectSrc + sourceRect.append(newRectSrc) + keyi = key sourceRecti = newRectSrc + + sourceRect = np.array(sourceRect, dtype=object) return sourceRect def buildAtlas(self):