Animation de spirale d'archimède
Bonjour
J'arrive à afficher des animations en cartésien.
J'arrive à afficher une spirale d’Archimède en polaires.
Je n'arrive pas à animer une spirale d'Archimède en polaires.
d'avance merci de votre aide.
Code:
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
|
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 19:19:13 2020
@author: julnar
Animation polaire archimède essai
R = f(THETA)
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
""
fig = plt.figure(figsize=(6,6))
ax = plt.subplot(111, polar=True)
""
rdata, tdata = [], [] # déclaration listes des X et Y à afficher
ln, = ax.plot(rdata, tdata) # affichage du fond
""
theta = np.linspace(0, 6.0*np.pi, 200) #theta en liste
""
# crér l'arrière de l'animation qui sera présent sur chaque image
def init():
ax.set_xlim(0, 2.0*np.pi)
ax.set_ylim(0,10)
ln.set_data(rdata,tdata)
return ln,
""
def update(frame):
# met la valeur x courante de frame
tdata.append(theta)
"place de la foncion ydata.append(f(frame)"
rdata.append(1.19*theta) # ro = f(theta) avec theta= frame
ln.set_data(rdata, tdata) # rempli line avec ro et theta courrants
return ln,
lenteur = 20 # lenteur de l'animation
anim = FuncAnimation(
fig, update, frames=theta,
init_func=init,blit=True, interval = lenteur,repeat=False) |