1

I'm working on a Hodgking-Huxley model of a neuron and I like to create a slider to see the results produced by changing some fixed parameters like maximal conductances. The plot is V vs t, which both are arrays, V is computed using an iteration that include the parameters I'd like to play with. After some time I created a slider, but I can make it to change the parameter defined. I've seen some examples where set_ydata is used, but they provide the complete Y-axis function as an argument, which (I think) is not posible in my case.

This is how I calculate V, being the first parameters the ones I want to change and the last part is the slider:

#Modelo de Hodgkin-Huxley


import pylab as pl
import numpy as np

A = 1

  for i in range(1,len(time)):
    dV= A*V[i-1]
    V[i] = V[i-1]+dV
pl.clf()
pl.subplot(311)
pl.title('Hodgkin-Huxley Model')
l, = pl.plot(time,V)

def update(val):
    l.set_ydata(V)
    A = sA.val

axA = pl.axes([0.13, 0.02, 0.75, 0.02])
sA = pl.Slider(axA, "A", 0, 200, valinit=A, color='#AAAAAA')
sA.on_changed(update)

The point is, I can create the slider, but when I use it, nothing changes in the plot.

user3415907
  • 11
  • 1
  • 3
  • Can you reduce this to the _minimal_ amount of code which will show your problem? What isn't working about this? – tacaswell Mar 13 '14 at 14:50
  • Ok, I think it is more clear this short. – user3415907 Mar 13 '14 at 14:55
  • Please strip out all of the science too (pains me to say that). Can you re-write it using a simpler model (like `y=m * x + b`) which will exercise the _code_ problem. – tacaswell Mar 13 '14 at 14:58
  • I don't share the idea that reducing the amount of information and reducing the length of a sample code is a good thing. Posters often don't give enough information in fact, so it is not a good way IMO to ask for a reduction as soon as a post seems a little dense. - The problem isn't a quantity problem but a quality of the info – eyquem Mar 13 '14 at 15:10

1 Answers1

1

Does this example work for you (see the top-rated answer).

They propose something similar to what you have done but here are the differences:

from pylab import *
from matplotlib.widgets import Slider

#define the plot objects
#TODO

#define the update method
def update(val):
   #do your update here
   pass

#create the slider
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)
samp.on_changed(update)

The reason yours might not work is because you aren't directly importing the Slider object. I hope this is of some use!

Community
  • 1
  • 1
Carlo M.
  • 331
  • 1
  • 3
  • 12