1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
print("")
print("")
print("SINUSOIDE EN MOUVEMENT")
print("")
print("On considère une fonction sinusoïdale d'équation : U*cos(2*pi*f*t + b)")
print("")
U = float(input("Quelle est l'amplitude de votre signal U (en V, et Umax < 10 V) ?"))
print("")
f = float(input("Quelle est la fréquence de votre signal f (en Hz) ?"))
b = -np.pi
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 1), ylim=(-5, 5))
line, = ax.plot([], [], lw=2)
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
# animation function. This is called sequentially
def animate(i):
x = np.linspace(0, 1, 1000)
y = U*np.sin(2 * np.pi * (f*x - 0.01*i))
line.set_data(x, y)
plt.grid()
plt.title("Onde mécanique en mouvement")
plt.xlabel("Temps en secondes")
plt.ylabel("Amplitude en Volt")
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=1000, interval=20, blit=True) |
Partager