I'd like to get some help fix an error

55 views
Skip to first unread message

clouda...@gmail.com

unread,
Jul 11, 2017, 10:52:45 PM7/11/17
to pyqtgraph
Hello. I'm trying to plot random walk values with an arrow that points the lastest value.

Here I attach my code that I made with the help of one of the module's great examples! I tested this under Python 3.6(32bit)

randomWalk function returns random walk values and update2 function puts them into a deque named data3.

It works well and I can see an arrow that follows the newest value plotting on the graph, but whenever I run the program, I see an error that sys:

Traceback (most recent call last):

File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\CurvePoint.py", line 64, in event

index = (len(x)-1) * np.clip(pos, 0.0, 1.0)

TypeError: object of type 'NoneType' has no len()

Traceback (most recent call last):

File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\CurvePoint.py", line 74, in event

i1 = np.clip(index-1, 0, len(x)-1)

TypeError: object of type 'NoneType' has no len()



I guess that the error might stem from the code curvePoint.setPos( len(data3) ), but I couldn't find out how to fix it.

I referred to the manual and Text Item, Arrow examples, but the arrows in the examples trace static formulas and I'm having trouble applying it to my real-time program.

I'd appreciate it if I could get some help on solving this problem.

Thank you for reading this.



from collections import deque

import pyqtgraph as pg

import numpy as np


t = 0

walk = 0


pg.setConfigOption('background', 'w')

pg.setConfigOption('foreground', 'k')


win = pg.GraphicsWindow()

win.setWindowTitle('pyqtgraph example: Scrolling Plots')


win.nextRow()

p3 = win.addPlot()


p3.setDownsampling(mode='peak')

p3.setClipToView(True)

p3.setRange(xRange=[-10000, 0])

p3.setLimits(xMax=0)

curve3 = p3.plot(pen=None, symbol='o', symbolPen=None, symbolSize=2, symbolBrush=(102, 000, 000, 255))


curvePoint = pg.CurvePoint(curve3)

arrow2 = pg.ArrowItem(angle=310)

arrow2.setParentItem(curvePoint)


data3 = deque()



def randomWalk():   

       global t, walk

       t = np.random.randint(-1,2)

       walk += t

       return walk


def update2():

       global data3, curvePoint

       data3.append( randomWalk() )

       if len(data3) <= 10000:

           curve3.setData(data3)

           curve3.setPos(-10000, 0)

           curvePoint.setPos( len(data3) )

       else:

           data3.popleft()

           curve3.setData(data3)

           curve3.setPos(-10000, 0)

           curvePoint.setPos( len(data3) )


def update():

      update2()


timer = pg.QtCore.QTimer()

timer.timeout.connect(update)

timer.start(1)



vas...@gmail.com

unread,
Jul 12, 2017, 6:33:40 AM7/12/17
to pyqt...@googlegroups.com
You need to initially set some data when defining the curve:

Cheers,
Vasilije




from collections import deque
import pyqtgraph as pg
import numpy as np

t = 0
walk = 0

pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')

win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: Scrolling Plots')

win.nextRow()
p3 = win.addPlot()

p3.setDownsampling(mode='peak')
p3.setClipToView(True)
p3.setRange(xRange=[-10000, 0])
p3.setLimits(xMax=0)
curve3 = p3.plot(pen=None, symbol='o', symbolPen=None, symbolSize=2, symbolBrush=(102, 000, 000, 255))
#  new:
curve3.setData([0],[0])
#  new:
from pyqtgraph import QtGui
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()





--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/819d65af-94b9-477a-ad35-66ace730e472%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

clouda...@gmail.com

unread,
Jul 12, 2017, 11:41:36 PM7/12/17
to pyqtgraph
Thank you so much for your help! It works well now!

I hope you will have a good day!
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages