Single-event-mode plotting

P

priisdk

I have some questions on the example below. My intention is to replace the y values with data from some sensor connected to the computer, and to make it work in what could be called 'single-event-mode' which means that I onlywant to plot and store data whenever the mouse is clicked.
I have made the plotting with VPython, and I have also considered matplotlib.
However, with either of these modules I cannot see how to answer the questions 1 and 2 below.
Is there some other graphical module that will be better suited?
Notice, that I use Python 3.2.

1) Can I modify the program so that the clicks should be done in the testdisplay window on not in the scene window?

2) In the testdisplay I only want to see the actual blue point together with the hitherto stored green points. And not only that: I want to free all earlier blue points from memory. How can I do that?



Poul Riis



from time import *
import visual.graph as visualgraph
from visual import *

scene=display(x=0, y=0, width=300, height=100,foreground=color.black,
background=color.white)
ch=''
txt=''
inputtext='tmax: '
labeltext=label(pos=(0,0,0),text=inputtext)
while ch!='\n':
ch=scene.kb.getkey()
txt=txt+ch
if ch!='\n':
labeltext.text=inputtext+txt
tmax=eval(txt)
#labeltext.visible=0


testdisplay=visualgraph.gdisplay(title='Test', xtitle='x', ytitle='y',
x=0, y=75, width=500, height=500,foreground=color.black,
background=color.white)
testcurve = visualgraph.gcurve(color=color.blue,display=testdisplay)
testdots = visualgraph.gdots(color=color.red,display=testdisplay,size=5)
mousedots = visualgraph.gdots(color=color.green,display=testdisplay,size=10)
finalcurve = visualgraph.gcurve(color=color.magenta,display=testdisplay)

tarray=[]
yarray=[]
tstart=time()
t=time()-tstart
while t<tmax:
rate(10)
t=time()-tstart
y=sin(5*pi*t/tmax)
nevents=scene.mouse.events
testcurve.plot(pos=(t,y))
testdots.plot(pos=(t,y))
if nevents>1:
mousedots.plot(pos=(t,y))
scene.mouse.events = 0
tarray.append(t)
yarray.append(y)
for i in range(0,len(tarray)):
finalcurve.plot(pos=(tarray,yarray))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top