# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # figure = tout le contenu de la fenêtre fig = plt.figure() # A appeler avant de # tracer autre chose # Une courbe fixe x = np.linspace(0, 10 * np.pi, 500) y1 = np.cos(x) parfait = plt.plot(x, y1) y2 = y1 # Pas d'amortissement pour l'instant amorti = plt.plot(x, y2) plt.title('Oscillateurs libre et amorti') plt.xlabel('x') plt.ylabel('y = f(x)') # Fonction appelée à chaque pas de l'animation def animate(i): C = i + 1 # i vaut successivement 0, 1, 2, ... # On peut changer le titre plt.title('Oscillateurs libre et amorti (C = ' + str(C) + ')') # Et changer les données y2 = np.exp(-x / float(C)) * y1 # Attention, amorti est une liste a 1 élément. amorti[0].set_data(x, y2) ani = animation.FuncAnimation(fig, animate, interval=100) plt.show()