diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index e39b535a..d7eb2bfc 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -431,7 +431,7 @@ class ScatterPlotItem(GraphicsObject): if len(args) == 1 and (isinstance(args[0], np.ndarray) or isinstance(args[0], list)): pens = args[0] - if kargs['mask'] is not None: + if 'mask' in kargs and kargs['mask'] is not None: pens = pens[kargs['mask']] if len(pens) != len(dataSet): raise Exception("Number of pens does not match number of points (%d != %d)" % (len(pens), len(dataSet))) @@ -453,7 +453,7 @@ class ScatterPlotItem(GraphicsObject): if len(args) == 1 and (isinstance(args[0], np.ndarray) or isinstance(args[0], list)): brushes = args[0] - if kargs['mask'] is not None: + if 'mask' in kargs and kargs['mask'] is not None: brushes = brushes[kargs['mask']] if len(brushes) != len(dataSet): raise Exception("Number of brushes does not match number of points (%d != %d)" % (len(brushes), len(dataSet))) diff --git a/pyqtgraph/graphicsItems/tests/ScatterPlotItem.py b/pyqtgraph/graphicsItems/tests/ScatterPlotItem.py deleted file mode 100644 index ef8271bf..00000000 --- a/pyqtgraph/graphicsItems/tests/ScatterPlotItem.py +++ /dev/null @@ -1,23 +0,0 @@ -import pyqtgraph as pg -import numpy as np -app = pg.mkQApp() -plot = pg.plot() -app.processEvents() - -# set view range equal to its bounding rect. -# This causes plots to look the same regardless of pxMode. -plot.setRange(rect=plot.boundingRect()) - - -def test_modes(): - 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]) - - -if __name__ == '__main__': - test_modes() diff --git a/pyqtgraph/graphicsItems/tests/ViewBox.py b/pyqtgraph/graphicsItems/tests/ViewBox.py deleted file mode 100644 index 91d9b617..00000000 --- a/pyqtgraph/graphicsItems/tests/ViewBox.py +++ /dev/null @@ -1,95 +0,0 @@ -""" -ViewBox test cases: - -* call setRange then resize; requested range must be fully visible -* lockAspect works correctly for arbitrary aspect ratio -* autoRange works correctly with aspect locked -* call setRange with aspect locked, then resize -* AutoRange with all the bells and whistles - * item moves / changes transformation / changes bounds - * pan only - * fractional range - - -""" - -import pyqtgraph as pg -app = pg.mkQApp() - -imgData = pg.np.zeros((10, 10)) -imgData[0] = 3 -imgData[-1] = 3 -imgData[:,0] = 3 -imgData[:,-1] = 3 - -def testLinkWithAspectLock(): - global win, vb - win = pg.GraphicsWindow() - vb = win.addViewBox(name="image view") - vb.setAspectLocked() - vb.enableAutoRange(x=False, y=False) - p1 = win.addPlot(name="plot 1") - p2 = win.addPlot(name="plot 2", row=1, col=0) - win.ci.layout.setRowFixedHeight(1, 150) - win.ci.layout.setColumnFixedWidth(1, 150) - - def viewsMatch(): - r0 = pg.np.array(vb.viewRange()) - r1 = pg.np.array(p1.vb.viewRange()[1]) - r2 = pg.np.array(p2.vb.viewRange()[1]) - match = (abs(r0[1]-r1) <= (abs(r1) * 0.001)).all() and (abs(r0[0]-r2) <= (abs(r2) * 0.001)).all() - return match - - p1.setYLink(vb) - p2.setXLink(vb) - print "link views match:", viewsMatch() - win.show() - print "show views match:", viewsMatch() - img = pg.ImageItem(imgData) - vb.addItem(img) - vb.autoRange() - p1.plot(x=imgData.sum(axis=0), y=range(10)) - p2.plot(x=range(10), y=imgData.sum(axis=1)) - print "add items views match:", viewsMatch() - #p1.setAspectLocked() - #grid = pg.GridItem() - #vb.addItem(grid) - pg.QtGui.QApplication.processEvents() - pg.QtGui.QApplication.processEvents() - #win.resize(801, 600) - -def testAspectLock(): - global win, vb - win = pg.GraphicsWindow() - vb = win.addViewBox(name="image view") - vb.setAspectLocked() - img = pg.ImageItem(imgData) - vb.addItem(img) - - -#app.processEvents() -#print "init views match:", viewsMatch() -#p2.setYRange(-300, 300) -#print "setRange views match:", viewsMatch() -#app.processEvents() -#print "setRange views match (after update):", viewsMatch() - -#print "--lock aspect--" -#p1.setAspectLocked(True) -#print "lockAspect views match:", viewsMatch() -#p2.setYRange(-200, 200) -#print "setRange views match:", viewsMatch() -#app.processEvents() -#print "setRange views match (after update):", viewsMatch() - -#win.resize(100, 600) -#app.processEvents() -#vb.setRange(xRange=[-10, 10], padding=0) -#app.processEvents() -#win.resize(600, 100) -#app.processEvents() -#print vb.viewRange() - - -if __name__ == '__main__': - testLinkWithAspectLock() diff --git a/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py b/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py new file mode 100644 index 00000000..eb5e43c6 --- /dev/null +++ b/pyqtgraph/graphicsItems/tests/test_ScatterPlotItem.py @@ -0,0 +1,54 @@ +import pyqtgraph as pg +import numpy as np +app = pg.mkQApp() +plot = pg.plot() +app.processEvents() + +# set view range equal to its bounding rect. +# This causes plots to look the same regardless of pxMode. +plot.setRange(rect=plot.boundingRect()) + + +def test_scatterplotitem(): + 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]) + + # Test uniform spot updates + s.setSize(10) + s.setBrush('r') + s.setPen('g') + s.setSymbol('+') + app.processEvents() + + # Test list spot updates + s.setSize([10] * 6) + s.setBrush([pg.mkBrush('r')] * 6) + s.setPen([pg.mkPen('g')] * 6) + s.setSymbol(['+'] * 6) + s.setPointData([s] * 6) + app.processEvents() + + # Test array spot updates + s.setSize(np.array([10] * 6)) + s.setBrush(np.array([pg.mkBrush('r')] * 6)) + s.setPen(np.array([pg.mkPen('g')] * 6)) + s.setSymbol(np.array(['+'] * 6)) + s.setPointData(np.array([s] * 6)) + app.processEvents() + + # Test per-spot updates + spot = s.points()[0] + spot.setSize(20) + spot.setBrush('b') + spot.setPen('g') + spot.setSymbol('o') + spot.setData(None) + + +if __name__ == '__main__': + test_scatterplotitem()