我是PyQtGraph的新手,想用它快速可视化我的数据采集。以前我使用的是matplotlib,其中重绘图形是我的瓶颈。在转换到PyQtGraph之后,我目前只缺少matplotlib的一个功能。也就是说,返回鼠标光标的x-和y-坐标。
如何调用/模拟使用PyQtGraph绘制的绘图中鼠标光标的x和y坐标的返回?
编辑!-在实现了leongold的提示之后,代码能够在不损失速度的情况下返回mousecursor位置。代码如下:import numpy
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
def gaussian(A, B, x):
return A * numpy.exp(-(x/(2. * B))**2.)
def mouseMoved(evt):
mousePoint = p.vb.mapSceneToView(evt[0])
label.setText(”
x = %0.2f,
y = %0.2f
” % (mousePoint.x(), mousePoint.y()))
# Initial data frame
x = numpy.linspace(-5., 5., 10000)
y = gaussian(5., 0.2, x)
# Generate layout
win = pg.GraphicsWindow()
label = pg.LabelItem(justify = “right”)
win.addItem(label)
p = win.addPlot(row = 1, col = 0)
plot = p.plot(x, y, pen = “y”)
proxy = pg.SignalProxy(p.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)
# Update layout with new data
i = 0
while i < 500:
noise = numpy.random.normal(0, .2, len(y))
y_new = y + noise
plot.setData(x, y_new, pen = “y”, clear = True)
p.enableAutoRange(“xy”, False)
pg.QtGui.QApplication.processEvents()
i += 1
win.close()