NoneType ERROR

44 views
Skip to first unread message

Wahabo Ouedraogo

unread,
Oct 9, 2021, 9:26:59 AM10/9/21
to pyqtgraph
if i run this code i get the following error which i don't understand:
Traceback (most recent call last):
   File "d: \ PyQt \ VS Code \ crosshair_example.py", line 45, in <module>
     Plot_Item.scene (). SigMouseMoved.connect (mouseMoved)
AttributeError: 'NoneType' object has no attribute 'sigMouseMoved'
PS D: \ PlattFomio Projects \ Arduino Memory Project>

This is the code : 

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point
from pyqtgraph.graphicsItems import PlotItem
import sys

app = pg.mkQApp("Crosshair Example")

data1 = 10000 + 15000 * pg.gaussianFilter(np.random.random(size=100), 10) + 3000 * np.random.random(size=100)

Plot_Item = pg.PlotItem()

label = pg.LabelItem(justify='right')

Plot_Item.addItem(label)
Plot_Item.plot(data1)



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

Plot_Item.addItem(vLine, ignoreBounds=True)
Plot_Item.addItem(hLine, ignoreBounds=True)


vb = Plot_Item.vb

def mouseMoved(evt):
    pos = evt
    if Plot_Item.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())
        hLine.setPos(mousePoint.y())  
           
Plot_Item.scene().sigMouseMoved.connect(mouseMoved)

if __name__ == '__main__':
    pg.exec()

Ognyan Moore

unread,
Nov 22, 2021, 6:34:01 PM11/22/21
to pyqtgraph
Hi, sorry I didn't reply earlier, you might have to call Plot_Item.show() first so the scene gets generated/attached.

Wahabo Ouedraogo

unread,
Nov 25, 2021, 11:04:06 AM11/25/21
to pyqtgraph
Thank you very much, the problem is solved
Reply all
Reply to author
Forward
0 new messages