Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To be honest, you made a little mess with the axis positioning and on the update function. I took the liberty to write again the plotting part and put the comment in there:</p> <pre><code># run your simulation like usual runSimulation() #create a ordered grid of axes, not one in top of the others axcolor = 'lightgoldenrodyellow' fig = p.figure() axdata = p.subplot2grid((7,4),(0,0),colspan=4,rowspan=4) axpos = p.subplot2grid((7,4),(-2,0),colspan=4, axisbg=axcolor) axvel = p.subplot2grid((7,4),(-1,0),colspan=4, axisbg=axcolor) # create your plots in the global space. # you are going to reference these lines, so you need to make them visible # to the update functione, instead of creating them inside a function # (and thus losing them at the end of the function) x = range(width) lpos, = axdata.plot(x,yPosition,'r') lvel, = axdata.plot(x,yVelocity,'g') ltarget, = axdata.plot(x,yTarget,'k') lforce, = axdata.plot(x,yForce,'b') # same as usual spos = Slider(axpos, 'Position Gain', 1.0, 20.0, valinit=1.5) svel = Slider(axvel, 'Velocity Gain', 5.0, 500.0, valinit=60.0) def update(val): # you don't need to declare the variables global, as if you don't # assign a value to them python will recognize them as global # without problem runSimulation(round(spos.val,2),round(svel.val,2)) lpos.set_ydata(yPosition) lvel.set_ydata(yVelocity) ltarget.set_ydata(yTarget) lforce.set_ydata(yForce) # you need to update only the canvas of the figure fig.canvas.draw() spos.on_changed(update) svel.on_changed(update) p.show() </code></pre> <p>By the way, if you want to simulate an damped oscillation, I strongly suggest you to give a look to the integrate module of scipy, wich contain the odeint function to integrate differential equation in a better way than what are you doing (that is called Euler integration, and is really error-prone)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload