import numpy
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [21, 7.77]
from IPython.core.display import HTML
from matplotlib import animation, rc
from IPython.display import HTML
from IPython.display import clear_output
from matplotlib.pyplot import figure
import matplotlib
matplotlib.rcParams['animation.embed_limit'] = 2**128
HTML("""
<style>
.output_png {
display: table-cell;
text-align: center;
vertical-align: middle;
}
</style>
""")
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
An integrate-and-fire oscillator is a system that integrates a function until some threshold value is reached, at which point the system "fires" and the integrator is reset to zero. An animation of such a system is shown below. These systems have been used to model neurons, pacemaker cells in hearts, and other biological systems that synchronize [1].
x = numpy.arange(0, 100, 1)
red_position = 0
# First set up the figure, the axis, and the plot element we want to animate
fig, ax = plt.subplots(figsize=(21, 7.77))
ax.set_xlim((0, 100))
ax.set_ylim((-1, 11))
ann = ax.annotate("firing threshold", xy=(1, 10.1), xytext=(1, 10.1), fontsize=18)
ax.set_title('An integrate-and-fire oscillator', fontsize=28)
ax.set_xlabel('time', fontsize=18)
ax.set_ylabel('$\sqrt{time}$', fontsize=18)
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
line, = ax.plot(x, numpy.sqrt(x))
line1, = ax.plot([],[], 'r.', alpha=0.7, markersize=30)
line2, = ax.plot(x, numpy.ones(len(x))*10, 'b--', linewidth=0.5)
# initialization function: plot the background of each frame
def init():
line.set_data(x, numpy.sqrt(x))
line1.set_data(x[red_position], [numpy.sqrt(x[red_position])])
line2.set_data(x, numpy.ones(len(x))*10)
return (line, line1, line2, )
def animate(i):
line.set_data(x, numpy.sqrt(x))
line2.set_data(x, numpy.ones(len(x))*10)
global red_position
red_position = (red_position + 1)%100
line1.set_data([x[red_position]], [numpy.sqrt(x[red_position])])
return (line, line1, line2, )
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
rc('animation', html='jshtml')
plt.close()
anim