""" Animation recipe 1. This is the simplest approach, where we just show the animation as the program runs, and then it stops without saving any files. """ import matplotlib.pyplot as plt import numpy as np def f(x, m, s): return (1.0/(np.sqrt(2*np.pi)*s))*np.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) # f er maks for x=m (mindre s gir større maksverdi) max_f = f(m, m, s_stop) y = f(x, m, s_stop) lines = plt.plot(x,y) # Returnerer en liste med linje-objekter! plt.axis([x[0], x[-1], -0.1, max_f]) plt.xlabel('x') plt.ylabel('f') for s in s_values: y = f(x, m, s) lines[0].set_ydata(y) # oppdater plottdata og tegn på nytt plt.draw() plt.pause(0.1)