Thank you so much for your help! It works well now! 

I hope you will have a good day!

On Wednesday, July 12, 2017 at 7:33:40 PM UTC+9, Vasilije Mehandzic wrote:

> 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])
>
> 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)
>
> #  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_()
>
>
>
>
>
> On Wed, Jul 12, 2017 at 4:52 AM, <[email protected] <javascript:>> 
> wrote:
>
>> 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)
>>
>>
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pyqtgraph/819d65af-94b9-477a-ad35-66ace730e472%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/pyqtgraph/819d65af-94b9-477a-ad35-66ace730e472%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/e28cc5b1-7f33-487e-9580-2f5ec2f5c773%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to