我是靠谱客的博主 清脆蜜粉,最近开发中收集的这篇文章主要介绍python画十字_python – 如何在pyqtgraph中绘制十字准线并绘制鼠标位置?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

我是

Python和pyqtgraph的新手.我正在为不同类型的信号工作.当我想在鼠标位置包含十字准线和文本标签时,我会陷入困境.我正在使用GridLayout,因为稍后该图表将与其他几个元素结合使用.

我尝试调整pyqtgraph示例十字线/鼠标交互但除了pyqtgraph中的许多其他东西我不明白vm = signalgraph.vb在mousemoved()之前的含义并且脚本引发了一个NameError

from pyqtgraph.Qt import QtGui, QtCore

import numpy as np

import pyqtgraph as pg

#QtGui.QApplication.setGraphicsSystem('raster')

app = QtGui.QApplication([])

mainwindow = QtGui.QMainWindow()

mainwindow.setWindowTitle('pyqtgraph example: PlotWidget')

mainwindow.resize(1000,800)

cw = QtGui.QWidget()

mainwindow.setCentralWidget(cw)

gridlayout = QtGui.QGridLayout()

cw.setLayout(gridlayout)

# define plot windows

signalgraph = pg.PlotWidget(name='Signalgraph')

# set position and size of plot windows

gridlayout.addWidget(signalgraph,0,0)

mainwindow.show()

# sample data

x = [0,1,2,3,4,5,6,7,8,9,10]

y = [0,0,0,8,8,8,9,9,9,0,0]

# plot 1

curve = pg.PlotCurveItem(x,y[:-1],pen='w',stepMode=True)

signalgraph.addItem(curve)

#cross hair in signalgraph

vLine = pg.InfiniteLine(angle=90, movable=False)

hLine = pg.InfiniteLine(angle=0, movable=False)

signalgraph.addItem(vLine, ignoreBounds=True)

signalgraph.addItem(hLine, ignoreBounds=True)

# Here I am not sure what to do ...

vb = signalgraph.vb

##vb = pg.ViewBox()

def mouseMoved(evt):

pos = evt[0]

if signalgraph.sceneBoundingRect().contains(pos):

mousePoint = vb.mapSceneToView(pos)

index = int(mousePoint.x())

if index > 0 and index < len(x):

label.setText("x=%0.1f, y1=%0.1f" % (mousePoint.x(), y[index], data2[index]))

vLine.setPos(mousePoint.x())

hLine.setPos(mousePoint.y())

proxy = pg.SignalProxy(signalgraph.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)

signalgraph.scene().sigMouseMoved.connect(mouseMoved)

# Start Qt event loop unless running in interactive mode or using pyside.

if __name__ == '__main__':

import sys

if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):

QtGui.QApplication.instance().exec_()

非常感谢

问候

迈克尔

最后

以上就是清脆蜜粉为你收集整理的python画十字_python – 如何在pyqtgraph中绘制十字准线并绘制鼠标位置?的全部内容,希望文章能够帮你解决python画十字_python – 如何在pyqtgraph中绘制十字准线并绘制鼠标位置?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部