| 1 |
How to plot functions |
| 2 |
===================== |
| 3 |
|
| 4 |
Models of synapses and neurons are typically composed of a series of functions. |
| 5 |
To affirm their correct implementation a plot is often helpful. |
| 6 |
|
| 7 |
Consider the following membrane voltage dependent Hodgkin-Huxley equations:: |
| 8 |
|
| 9 |
from brian2 import * |
| 10 |
|
| 11 |
VT = -63*mV |
| 12 |
|
| 13 |
eq = Equations(""" |
| 14 |
alpha_m = 0.32*(mV**-1)*4*mV/exprel((13*mV-v+VT)/(4*mV))/ms : Hz |
| 15 |
beta_m = 0.28*(mV**-1)*5*mV/exprel((v-VT-40*mV)/(5*mV))/ms : Hz |
| 16 |
alpha_h = 0.128*exp((17*mV-v+VT)/(18*mV))/ms : Hz |
| 17 |
beta_h = 4./(1+exp((40*mV-v+VT)/(5*mV)))/ms : Hz |
| 18 |
alpha_n = 0.032*(mV**-1)*5*mV/exprel((15*mV-v+VT)/(5*mV))/ms : Hz |
| 19 |
beta_n = .5*exp((10*mV-v+VT)/(40*mV))/ms : Hz |
| 20 |
tau_n = 1/(alpha_n + beta_n) : second |
| 21 |
tau_m = 1/(alpha_m + beta_m) : second |
| 22 |
tau_h = 1/(alpha_h + beta_h) : second |
| 23 |
""") |
| 24 |
|
| 25 |
We can do the following to plot them as function of membrane voltage:: |
| 26 |
|
| 27 |
group = NeuronGroup(100, eq + Equations("v : volt")) |
| 28 |
group.v = np.linspace(-100, 100, len(group))*mV |
| 29 |
|
| 30 |
plt.plot(group.v/mV, group.tau_m[:]/ms, label="tau_m") |
| 31 |
plt.plot(group.v/mV, group.tau_n[:]/ms, label="tau_n") |
| 32 |
plt.plot(group.v/mV, group.tau_h[:]/ms, label="tau_h") |
| 33 |
plt.xlabel('membrane voltage / mV') |
| 34 |
plt.ylabel('tau / ms') |
| 35 |
plt.legend() |
| 36 |
|
| 37 |
.. image:: images/function_plot.png |
| 38 |
|
| 39 |
Note that we need to use ``[:]`` for the ``tau_...`` equations, because Brian cannot |
| 40 |
resolve the external constant ``VT`` otherwise. Alternatively we could have supplied |
| 41 |
the constant in the namespace of the `NeuronGroup`, see :doc:`/advanced/namespaces`. |