Animation Jupyter notebook

Bonjour
J'ai trouvé un moyen d'avoir des animations sur jupyter en utilisant %matplotlib notebook comme ceci
import numpy as np
import scipy.stats as st

%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation as animation
par exemple ici ça marche.
n = 100
X = st.norm(0,1).rvs(200)
number_of_frames = np.size(X)

def update_hist(num, second_argument):
    plt.cla()
    plt.hist(X[:num], bins = 20)
    plt.title("{}".format(num))
    plt.legend()

fig = plt.figure()
hist = plt.hist(X)

ani = animation.FuncAnimation(fig, update_hist, number_of_frames, fargs=(X, ), repeat = False )
plt.show()
Ce qui est très louche c'est que ici ça ne marche plus
N_max = 100
X = np.linspace(-5,5, N_max )
number_of_frames = np.size(X)
N = np.arange(1,N_max+1)
h = 1/np.sqrt(N)

def update_plot(n):
    #plt.cla()
    lines.set_data(X, np.array([f(x) for x in X]))
    lines2.set_data(X, np.array([fen(sample_sort[:n],h[n],x) for x in X]))
    ax.set_title("n = {}".format(n))
    return lines, lines2

fig = plt.figure()
ax = plt.axes(xlim=(-4, 4), ylim=(-0.01, 1))
lines, = ax.plot([], [], 'y-', lw=2, label="d")
lines2, = ax.plot([], [], 'b--', lw=3, label="f")

ani = animation.FuncAnimation(fig, update_plot, number_of_frames, repeat = False )
plt.show()
pourtant pour moi c'est la même chose.
Bien à vous.

Réponses

  • J'ai tenté une modification. Maintenant j'ai une courbe mais pas d'animation.
Connectez-vous ou Inscrivez-vous pour répondre.