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.

4
  • Can you reduce this to the minimal amount of code which will show your problem? What isn't working about this? Commented Mar 13, 2014 at 14:50
  • Ok, I think it is more clear this short. Commented Mar 13, 2014 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. Commented Mar 13, 2014 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 Commented Mar 13, 2014 at 15:10

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but still nothing happens.
In the example l.set_ydata(ampsin(2*pifreq*t)) is used. The ydata is a function. In my case I have an array V as ydata, so I can't just use that :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.