From 55a9e19e43bfe2b8863fa1f8b432ad1d974cee82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20G=C3=B6ries?= <43136580+dgoeries@users.noreply.github.com> Date: Wed, 21 Oct 2020 05:02:53 +0200 Subject: [PATCH] ScatterItem: Fix name setting (#1405) --- pyqtgraph/graphicsItems/ScatterPlotItem.py | 2 ++ .../tests/test_ScatterPlotItem.py | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index 1726f652..e55a4162 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -420,6 +420,8 @@ class ScatterPlotItem(GraphicsObject): newData['x'] = kargs['x'] newData['y'] = kargs['y'] + if 'name' in kargs: + self.opts['name'] = kargs['name'] if 'pxMode' in kargs: self.setPxMode(kargs['pxMode']) if 'antialias' in kargs: diff --git a/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py b/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py index ba1fb9d7..3eb70271 100644 --- a/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py @@ -1,31 +1,37 @@ from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import numpy as np -app = pg.mkQApp() -app.processEvents() - def test_scatterplotitem(): + app = pg.mkQApp() + app.processEvents() + plot = pg.PlotWidget() # set view range equal to its bounding rect. # This causes plots to look the same regardless of pxMode. plot.setRange(rect=plot.boundingRect()) # test SymbolAtlas accepts custom symbol - s = pg.ScatterPlotItem() + s = pg.ScatterPlotItem(name="Scatter") symbol = QtGui.QPainterPath() symbol.addEllipse(QtCore.QRectF(-0.5, -0.5, 1, 1)) - s.addPoints([{'pos': [0,0], 'data': 1, 'symbol': symbol}]) + s.addPoints([{'pos': [0, 0], 'data': 1, 'symbol': symbol}]) + + assert s.name() == "Scatter" for i, pxMode in enumerate([True, False]): for j, useCache in enumerate([True, False]): s = pg.ScatterPlotItem() s.opts['useCache'] = useCache plot.addItem(s) - s.setData(x=np.array([10,40,20,30])+i*100, y=np.array([40,60,10,30])+j*100, pxMode=pxMode) - s.addPoints(x=np.array([60, 70])+i*100, y=np.array([60, 70])+j*100, size=[20, 30]) + s.setData(x=np.array([10, 40, 20, 30]) + i * 100, + y=np.array([40, 60, 10, 30]) + j * 100, pxMode=pxMode, + name="MoreScatter") + s.addPoints(x=np.array([60, 70]) + i * 100, + y=np.array([60, 70]) + j * 100, size=[20, 30]) + assert s.name() == "MoreScatter" # Test uniform spot updates s.setSize(10) s.setBrush('r') @@ -62,6 +68,7 @@ def test_scatterplotitem(): def test_init_spots(): + app = pg.mkQApp() plot = pg.PlotWidget() # set view range equal to its bounding rect. # This causes plots to look the same regardless of pxMode.