我想在鼠标x位置后添加一条垂直线(工作),在曲线后添加一条水平线(而不是鼠标y)。在pyqtgraph十字线示例中,它显示了如何在鼠标\ux和鼠标\uy位置之后添加十字线。但这并没有多大帮助。 下面的代码将垂直线位置设置为鼠标位置。但是我不知道如何将水平线的位置设置为曲线当前的y位置(取决于鼠标x的位置)。你知道吗
data1 = 10000 + 15000 * pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * np.random.random(size=10000)
def mouseMoved(evt):
pos = evt[0]
if p1.sceneBoundingRect().contains(pos):
mousePoint = vb.mapSceneToView(pos)
index = int(mousePoint.x())
if index > 0 and index < len(data1):
label.setText("<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>y1=%0.1f</span>, <span style='color: green'>y2=%0.1f</span>" % (mousePoint.x(), data1[index], data2[index]))
vLine.setPos(mousePoint.x()) # here i set the vertical line's position to mouse_x position
#hLinePos = vb.mapToView( vLine.pos() )
hLine.setPos(data1[mousePoint.x()]) # <-- how do i set this horizontal line so it is kind of snaped to the curve
也许这个十字线小部件可以为你指明正确的方向
相关问题 更多 >
编程相关推荐