I am new to PyQtGraph and want to use it to quickly visualize my data collection. I used to use matplotlib where redrawing a shape was my bottleneck. After upgrading to PyQtGraph, I currently lack only one matplotlib functionality. Namely, returning the x- and y-coordinate of my mouse cursor.
How can I cause / imitate the return of the x- and y-coordinates of my mouse cursor in a graph made using PyQtGraph?
CHANGE! - After content injection, leongold code can return the mousecursor position without loss of speed. The code is as follows:
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("<span style='font-size: 14pt; color: white'> x = %0.2f, <span style='color: white'> y = %0.2f</span>" % (mousePoint.x(), mousePoint.y()))
x = numpy.linspace(-5., 5., 10000)
y = gaussian(5., 0.2, x)
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)
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()
source
share