示例#1
0
def animate(i):
    plt.clf()
    ti = t[i]
    print(ti)
    xi = [xp[:i + 1] for xp in x]  # On stocke l'avancement
    vi = [vp[:i + 1] for vp in v]  # jusqu'à l'instant présent
    plt.suptitle('Oscillateur de Landau, $t={}$'.format(round(ti, 2)))
    plt.subplot(3, 1, 1)  # Première sous-figure
    plt.plot([t[0], t[-1]], [np.sqrt(ell0**2 - d**2)] * 2, 'k')
    plt.ylabel('$x$')
    plt.title('Evolution temporelle de $x$ (en fonction de $t$)')
    for j in range(len(xi)):
        plt.plot(t[:i + 1], xi[j], color=colors[j])
    plt.ylim(max(0, min(x[-1])), xi[-1][0])
    if i < decalage: plt.xlim(0, t[decalage])
    else: plt.xlim(t[i - decalage], t[i])
    plt.subplot(3, 1, 2)  # Seconde sous-figure
    portrait_de_phase(xi,
                      vi,
                      fantome=50,
                      clearfig=False,
                      color=colors,
                      ylim=vlim)
    plt.xlabel('')
    plt.subplot(3, 1, 3)  # Troisième sous-figure
    diagramme_energetique(xi, vi, Em, color=colors, clearfig=False, fantome=50)
def animate(i):
    plt.clf()    
    ti = t[i]
    print(ti)
    xi = [xp[:i+1] for xp in x]   # On stocke l'avancement
    vi = [vp[:i+1] for vp in v]   # jusqu'à l'instant présent
    plt.suptitle('Oscillateur de Landau, $t={}$'.format(round(ti,2)))
    plt.subplot(3,1,1)            # Première sous-figure
    plt.plot([t[0],t[-1]],[np.sqrt(ell0**2-d**2)]*2,'k')
    plt.ylabel('$x$')
    plt.title('Evolution temporelle de $x$ (en fonction de $t$)')
    for j in range(len(xi)):
        plt.plot(t[:i+1],xi[j],color=colors[j])
    plt.ylim(max(0,min(x[-1])),xi[-1][0])
    if i < decalage: plt.xlim(0,t[decalage])
    else: plt.xlim(t[i-decalage],t[i])
    plt.subplot(3,1,2)            # Seconde sous-figure
    portrait_de_phase(xi,vi,fantome=50,clearfig=False,color=colors,ylim=vlim)
    plt.xlabel('')
    plt.subplot(3,1,3)            # Troisième sous-figure
    diagramme_energetique(xi,vi,Em,color=colors,clearfig=False,fantome=50)
def animate(i):
    plt.clf()
    ti = t[i]
    print(ti)
    xi = [xp[:i+1] for xp in x]   # On stocke l'avancement
    vi = [vp[:i+1] for vp in v]   # jusqu'à l'instant présent
    plt.suptitle('Pendule pesant, $t={}$'.format(round(ti,2)))
    plt.subplot(2,2,1)            # Première sous-figure
    plt.ylabel('$x$')
    plt.title('Evolution temporelle de $\\theta$ (en fonction de $t$)')
    for j in range(len(xi)):
        plt.plot(t[:i+1],xi[j],color=colors[j])
    xlim = min(x[-1]),xi[-1][0]
    plt.ylim(xlim)
    if i < decalage: plt.xlim(0,t[decalage])
    else: plt.xlim(t[i-decalage],t[i])
    plt.subplot(2,2,3)            # Seconde sous-figure
    portrait_de_phase(xi,vi,fantome=50,clearfig=False,color=colors,ylim=vlim,xlim=xlim)
    plt.xlabel('')
    plt.subplot(1,2,2)            # Troisième sous-figure
    diagramme_energetique(xi,vi,Em,color=colors,clearfig=False,fantome=50,xlim=xlim)
for xi,vi in zip(x0,v0):          # Itération sur les conditions initiales
    print(xi,vi)                  # Un peu de feedback
    sol = sp.integrate.odeint(landau,[xi,vi],t) # On intègre
    x.append(sol[:,0])            # et on stocke à la fois les positions
    v.append(sol[:,1])            # et les vitesses

fig = plt.figure(figsize=(10,10)) # Création de la figure

vlim = (np.min(v),np.max(v))      # Limites verticales (horizontales imposées par les CI)
base_name='PNG/M4_oscillateur_de_landau_tilte_portrait_de_phase'

for i,ti in enumerate(t):         # On regarde à chaque instant d'intégration
    print(ti)                     # Un peu de feedback
    xi = [xp[:i+1] for xp in x]   # On stocke l'avancement
    vi = [vp[:i+1] for vp in v]   # jusqu'à l'instant présent
    plt.suptitle('Oscillateur de Landau tilte, $t={}$'.format(round(ti,2)))
    plt.subplot(2,1,1)            # Première sous-figure
    portrait_de_phase(xi,vi,fantome=50,clearfig=False,color=colors,ylim=vlim)
    plt.xlabel('')
    plt.subplot(2,1,2)            # Seconde sous-figure
    diagramme_energetique(xi,vi,Em,color=colors,clearfig=False,fantome=50)
    plt.savefig('{}_{:04d}.png'.format(base_name,i))
    plt.clf()

from film import make_film        # Boîte à outil visuelle

make_film(base_name)              # et fabrication du film correspondant



fig = plt.figure(figsize=(10, 10))  # Création de la figure

th_lim = (np.min(th), np.max(th))  # Limites en theta
thp_lim = (np.min(thp), np.max(thp))  # Limites en theta point
base_name = 'PNG/M4_pendule_simple_portrait_de_phase_zoom'

for i, ti in enumerate(t):  # Affichage progressif
    print(ti)  # Un peu de feed back
    thi = [th_p[:i + 1] for th_p in th]  # On ne prend que jusqu'�
    thpi = [thp_p[:i + 1] for thp_p in thp]  # l'instant présent
    plt.suptitle('Pendule simple, $t={}$'.format(round(ti, 2)))
    plt.subplot(2, 1, 1)  # Sous-figure du haut
    portrait_de_phase(thi,
                      thpi,
                      fantome=20,
                      clearfig=False,
                      color=colors,
                      xlim=th_lim,
                      ylim=thp_lim)
    plt.xlabel('')
    plt.subplot(2, 1, 2)  # Sous-figure du bas
    diagramme_energetique(thi,
                          thpi,
                          Em,
                          color=colors,
                          clearfig=False,
                          fantome=20,
                          xlim=th_lim)
    plt.savefig('{}_{:04d}.png'.format(base_name, i))
    plt.clf()  # Nettoyage
示例#6
0
fig = plt.figure(figsize=(10, 10))  # Création de la figure

# Limites verticales (horizontales imposées par les CI)
vlim = (np.min(v), np.max(v))
base_name = 'PNG/M4_oscillateur_de_landau_portrait_de_phase'

for i, ti in enumerate(t):  # On regarde à chaque instant d'intégration
    print(ti)  # Un peu de feedback
    xi = [xp[:i + 1] for xp in x]  # On stocke l'avancement
    vi = [vp[:i + 1] for vp in v]  # jusqu'à l'instant présent
    plt.suptitle('Oscillateur de Landau, $t={}$'.format(round(ti, 2)))
    plt.subplot(2, 1, 1)  # Première sous-figure
    portrait_de_phase(xi,
                      vi,
                      fantome=50,
                      clearfig=False,
                      color=colors,
                      ylim=vlim)
    plt.xlabel('')
    plt.subplot(2, 1, 2)  # Seconde sous-figure
    diagramme_energetique(xi, vi, Em, color=colors, clearfig=False, fantome=50)
    plt.savefig('{}_{:04d}.png'.format(base_name, i))
    plt.clf()

from film import make_film  # Boîte à outil visuelle

make_film(base_name)  # et fabrication du film correspondant

os.system("pause")
    sol = sp.integrate.odeint(pendule, [thi, thpi], t)  # Intégration
    th.append(sol[:, 0])          # Ajout des positions
    thp.append(sol[:, 1])         # et vitesses correspondantes

fig = plt.figure(figsize=(10, 10))  # Création de la figure

th_lim = (np.min(th), np.max(th))  # Limites en theta
thp_lim = (np.min(thp), np.max(thp))  # Limites en theta point
base_name = 'PNG/M4_pendule_simple_portrait_de_phase_zoom'

for i, ti in enumerate(t):        # Affichage progressif
    print(ti)                    # Un peu de feed back
    thi = [th_p[:i + 1] for th_p in th]    # On ne prend que jusqu'à
    thpi = [thp_p[:i + 1] for thp_p in thp]  # l'instant présent
    plt.suptitle('Pendule simple, $t={}$'.format(round(ti, 2)))
    plt.subplot(2, 1, 1)           # Sous-figure du haut
    portrait_de_phase(thi, thpi, fantome=20, clearfig=False,
                      color=colors, xlim=th_lim, ylim=thp_lim)
    plt.xlabel('')
    plt.subplot(2, 1, 2)           # Sous-figure du bas
    diagramme_energetique(thi, thpi, Em, color=colors,
                          clearfig=False, fantome=20, xlim=th_lim)
    plt.savefig('{}_{:04d}.png'.format(base_name, i))
    plt.clf()                    # Nettoyage

from film import make_film       # Boîte à outil pour faire un film

make_film(base_name)             # et appel effectif

os.system("pause")