This is what it looks when you add pg.TextItems to each individual pg.ScatterPlotItem
using:
label = pg.TextItem(text=str(i), color=HEX_ORANGE, anchor=([1, 1]))
label.setPos(x, y)
self.plot.addItem(label)
but this can only be done in a for loop and that is slow... so i wanted to replace it with a faster solution. I found that replacing it with QPainterPath works for pg.ScatterPlotItem but i cannot get them to behave the same using:
from PySide6.QtGui import QTransform, QPainterPath, QFont
def genSymbol(label):
# Basically the example in pyqtgraph/examples/ScatterPlotItem
symbol = QPainterPath()
f = QFont()
f.setPointSize(5)
symbol.addText(0, 0, f, label)
br = symbol.boundingRect()
scale = min(1. / br.width(), 1. / br.height())
tr = QTransform()
tr.scale(scale, scale)
tr.translate(-br.x() - br.width()/2., -br.y() - br.height()/2.)
return symbol
if __name__ == '__main__':
import pyqtgraph as pg
from PySide6.QtWidgets import QMainWindow
from PySide6.QtGui import QColor
app = pg.mkQApp("PerPlotHelper")
w = QMainWindow()
cw = pg.GraphicsLayoutWidget()
w.show()
w.resize(600, 600)
w.setCentralWidget(cw)
w.setWindowTitle('pyqtgraph example: Arrow')
p = cw.addPlot(row=0, col=0)
####
point_xs = [1, 2, 3, 4, 5, 6]
point_ys = [1, 2, 3, 4, 5, 6]
points = pg.ScatterPlotItem(point_xs, point_ys,
symbol='o',
size=9,
pen=pg.mkPen(QColor("#ff9900")),
brush=pg.mkBrush(QColor("#ff9900")),
data="w/e")
p.addItem(points)
symbols = [genSymbol(str(i)) for i in range(len(point_xs))]
# Draw Text Label
spots = [{'x': point_xs[i],
'y': point_ys[i],
'data': "w/e",
'brush': "#ff9900",
'symbol': symbols[i]} for i in range(len(point_xs))]
textLabelsP = pg.ScatterPlotItem(pen=pg.mkPen('w'), pxMode=True)
textLabelsP.addPoints(spots)
p.addItem(textLabelsP)
app.exec()
only puts small, barely visible text on the top-right inside the point itself...
or with pxMode=False it produces this abomination:
What am i missing?
Thanks.