# -*- coding: utf-8 -*- from numpy import sin, cos, pi, array import numpy as np import matplotlib.pyplot as plt import scipy.integrate as integrate import matplotlib.animation as animation amplitude = 1 dt = 0.05 fig = plt.figure() # 111 : découpage 1x1, sous-figure numéro 1 # (i.e. pas de découpage, mais on doit utiliser add_subplot # pour utiliser xlim et ylim) ax = fig.add_subplot(111, autoscale_on=False, xlim=(-1.5, 1.5), ylim=(-1.5, .5)) ax.grid() x = [0, 0] y = [0, -1] # y = f(x). 'o-' pour afficher des ronds sur les points. parfait = plt.plot(x, y, 'o-') plt.title('Pendule') plt.xlabel('x') plt.ylabel('y') def animate(i): t = i * dt # t = 0, 0.05, 0.10, ... # On s'autorise quelques libertés par rapport # à la physique ... angle = sin(t) * amplitude x = (0, sin(angle)) y = (0, -cos(angle)) plt.title('Pendule parfait (t = ' + str(round(t * 10) / float(10)) + ')') # Attention, parfait est une liste a 1 élément. parfait[0].set_data(x, y) ani = animation.FuncAnimation(fig, animate, interval=10) plt.show()