From dbdd5d9a395befc6b589b55f5c625efa7c77812e Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Wed, 10 Jun 2020 23:03:43 -0700 Subject: [PATCH] Peque scatter symbols (#1244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added arrow symbols for the ScatterPlotItem * Fixed arrows rotation in scatter plots * Added new symbols to example Co-authored-by: Miguel Sánchez de León Peque --- examples/ScatterPlot.py | 3 +-- examples/Symbols.py | 4 ++++ pyqtgraph/graphicsItems/ScatterPlotItem.py | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/ScatterPlot.py b/examples/ScatterPlot.py index 93f184f2..ea86bd19 100644 --- a/examples/ScatterPlot.py +++ b/examples/ScatterPlot.py @@ -83,7 +83,7 @@ random_str = lambda : (''.join([chr(np.random.randint(ord('A'),ord('z'))) for i s2 = pg.ScatterPlotItem(size=10, pen=pg.mkPen('w'), pxMode=True) pos = np.random.normal(size=(2,n), scale=1e-5) -spots = [{'pos': pos[:,i], 'data': 1, 'brush':pg.intColor(i, n), 'symbol': i%5, 'size': 5+i/10.} for i in range(n)] +spots = [{'pos': pos[:,i], 'data': 1, 'brush':pg.intColor(i, n), 'symbol': i%10, 'size': 5+i/10.} for i in range(n)] s2.addPoints(spots) spots = [{'pos': pos[:,i], 'data': 1, 'brush':pg.intColor(i, n), 'symbol': label[1], 'size': label[2]*(5+i/10.)} for (i, label) in [(i, createLabel(*random_str())) for i in range(n)]] s2.addPoints(spots) @@ -120,4 +120,3 @@ if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_() - diff --git a/examples/Symbols.py b/examples/Symbols.py index 417df35e..a0c57f75 100755 --- a/examples/Symbols.py +++ b/examples/Symbols.py @@ -29,6 +29,10 @@ plot.plot([7, 8, 9, 10, 11], pen=(217,83,25), symbolBrush=(217,83,25), symbolPen plot.plot([8, 9, 10, 11, 12], pen=(237,177,32), symbolBrush=(237,177,32), symbolPen='w', symbol='star', symbolSize=14, name="symbol='star'") plot.plot([9, 10, 11, 12, 13], pen=(126,47,142), symbolBrush=(126,47,142), symbolPen='w', symbol='+', symbolSize=14, name="symbol='+'") plot.plot([10, 11, 12, 13, 14], pen=(119,172,48), symbolBrush=(119,172,48), symbolPen='w', symbol='d', symbolSize=14, name="symbol='d'") +plot.plot([11, 12, 13, 14, 15], pen=(253, 216, 53), symbolBrush=(253, 216, 53), symbolPen='w', symbol='arrow_down', symbolSize=22, name="symbol='arrow_down'") +plot.plot([12, 13, 14, 15, 16], pen=(189, 189, 189), symbolBrush=(189, 189, 189), symbolPen='w', symbol='arrow_left', symbolSize=22, name="symbol='arrow_left'") +plot.plot([13, 14, 15, 16, 17], pen=(187, 26, 95), symbolBrush=(187, 26, 95), symbolPen='w', symbol='arrow_up', symbolSize=22, name="symbol='arrow_up'") +plot.plot([14, 15, 16, 17, 18], pen=(248, 187, 208), symbolBrush=(248, 187, 208), symbolPen='w', symbol='arrow_right', symbolSize=22, name="symbol='arrow_right'") plot.setXRange(-2, 4) ## Start Qt event loop unless running in interactive mode or using pyside. diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index af6efcc8..1140c36f 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from itertools import starmap, repeat try: from itertools import imap @@ -20,7 +21,9 @@ __all__ = ['ScatterPlotItem', 'SpotItem'] ## Build all symbol paths -Symbols = OrderedDict([(name, QtGui.QPainterPath()) for name in ['o', 's', 't', 't1', 't2', 't3','d', '+', 'x', 'p', 'h', 'star']]) +name_list = ['o', 's', 't', 't1', 't2', 't3', 'd', '+', 'x', 'p', 'h', 'star', + 'arrow_up', 'arrow_right', 'arrow_down', 'arrow_left'] +Symbols = OrderedDict([(name, QtGui.QPainterPath()) for name in name_list]) Symbols['o'].addEllipse(QtCore.QRectF(-0.5, -0.5, 1, 1)) Symbols['s'].addRect(QtCore.QRectF(-0.5, -0.5, 1, 1)) coords = { @@ -41,7 +44,11 @@ coords = { 'star': [(0, -0.5), (-0.1123, -0.1545), (-0.4755, -0.1545), (-0.1816, 0.059), (-0.2939, 0.4045), (0, 0.1910), (0.2939, 0.4045), (0.1816, 0.059), (0.4755, -0.1545), - (0.1123, -0.1545)] + (0.1123, -0.1545)], + 'arrow_down': [ + (-0.125, 0.125), (0, 0), (0.125, 0.125), + (0.05, 0.125), (0.05, 0.5), (-0.05, 0.5), (-0.05, 0.125) + ] } for k, c in coords.items(): Symbols[k].moveTo(*c[0]) @@ -51,7 +58,10 @@ for k, c in coords.items(): tr = QtGui.QTransform() tr.rotate(45) Symbols['x'] = tr.map(Symbols['+']) - +tr.rotate(45) +Symbols['arrow_right'] = tr.map(Symbols['arrow_down']) +Symbols['arrow_up'] = tr.map(Symbols['arrow_right']) +Symbols['arrow_left'] = tr.map(Symbols['arrow_up']) def drawSymbol(painter, symbol, size, pen, brush): if symbol is None: