从pyqtgraph中的散点图中获取各个点及其属性,可以通过以下步骤实现:
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="Scatter Plot")
plot = win.addPlot()
import numpy as np
x = np.random.normal(size=100)
y = np.random.normal(size=100)
scatter = pg.ScatterPlotItem(x=x, y=y, size=10, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 120))
plot.addItem(scatter)
def mouseClick(event):
pos = event.pos()
points = scatter.pointsAt(pos)
if len(points) > 0:
point = points[0]
print("Clicked point:", point.pos())
print("Point attributes:", point.data())
plot.scene().sigMouseClicked.connect(mouseClick)
win.show()
app.exec_()
通过以上步骤,可以实现从pyqtgraph中的散点图中获取各个点及其属性。当鼠标点击散点图中的点时,回调函数会打印出被点击点的位置和属性信息。
关于pyqtgraph的更多信息和使用方法,可以参考腾讯云的相关产品介绍链接地址:pyqtgraph产品介绍
领取专属 10元无门槛券
手把手带您无忧上云