from numpy import * from matplotlib.pyplot import * from matplotlib.animation import FuncAnimation def f(x, m, s): return (1.0/(sqrt(2*pi)*s))*exp(-0.5*((x-m)/s)**2) m = 0; s_start = 2; s_stop = 0.2 s_values = np.linspace(s_start, s_stop, 30) x = np.linspace(m -3*s_start, m + 3*s_start, 1000) max_f = f(m, m, s_stop) lines = plot([],[]) #empty plot to create the lines object #function to initialize plot: def init(): axis([x[0], x[-1], -0.1, max_f]) lines[0].set_xdata(x) return lines #for updating the plot: def update(frame): y = f(x, m, frame) lines[0].set_ydata(y) return lines ani = FuncAnimation(gcf(), update, frames=s_values, init_func=init, blit=True) ani.save('test.gif') show()