Attempt number 2 is to make a custom qpainterpath for each spot and treat
all separate areas like their own spots.
The examples widget shows how to do this with text, so I tried to do the
same thing with a list of vertices. However, the output symbol is vert tiny
and doesn't look correct. Any pointers?
import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets, QtCore, QtGui
import numpy as np
tri = np.array([[0,0], [0,5], [5,5], [0,0]])
tris = []
xyLocs = []
datas = []
for ii in np.arange(0, 16, 5):
curTri = tri + ii
tris.append(curTri)
xyLocs.append(curTri.min(0))
datas.append(ii)
def ptsClicked(item, pts):
print(f'ID {pts[0].data()} Clicked!')
def makeSymbol(verts: np.ndarray):
outSymbol = QtGui.QPainterPath()
symPath = pg.arrayToQPath(*verts.T)
outSymbol.addPath(symPath)
# From pyqtgraph.examples for plotting text
br = outSymbol.boundingRect()
scale = min(1./br.width(), 1./br.height())
tr = QtGui.QTransform()
tr.scale(scale, scale)
tr.translate(-br.x() - br.width()/2., -br.y() - br.height()/2.)
outSymbol = tr.map(outSymbol)
return outSymbol
app = pg.mkQApp()
symbs = []
for xyLoc, tri in zip(xyLocs, tris):
symbs.append(pg.arrayToQPath(*tri.T))
xyLocs = np.vstack(xyLocs)
tri2 = pg.PlotDataItem(*xyLocs.T, symbol=symbs, data=datas)
# Now each 'point' is one of the triangles, hopefully
tri2.sigPointsClicked.connect(ptsClicked)
w = pg.PlotWindow()
w.plotItem.addItem(tri2)
w.show()
app.exec()
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/9cb3a01f-7390-4b03-b19e-29c9ab377945o%40googlegroups.com.