Matplotlib animation
Bonjour
Dans le code suivant, je stocke des histogrammes et des plots pour les afficher. Je n'obtiens pas d'animation, je ne comprends pas pourquoi. Avez-vous une idée ?
Dans le code suivant, je stocke des histogrammes et des plots pour les afficher. Je n'obtiens pas d'animation, je ne comprends pas pourquoi. Avez-vous une idée ?
import numpy as np import scipy.stats as st %matplotlib notebook import matplotlib.pyplot as plt import matplotlib.animation as animation def Metropolis(pi,Q,tps_max,X0, display): """ d """ X = np.zeros(tps_max) X[0] = X0 if display: ims=[] # list of images for animation fig,axs = plt.subplots(1,2) for tps in range(1,tps_max): y = np.random.rand() # Tiré y selon Q(Xn,y) U = np.random.rand()# Tirer U hasard sur [0,1] if U < np.min( np.array([pi(y)/pi(X[tps-1]), 1])) :# Si U < R(Xn,y) accepter la sélection X[tps] = y else: X[tps] = X[tps-1] # Sinon refuser la sélection (Rabiot) if tps %100 == 0: print('Etape {}/{}'.format(tps,tps_max)) if display: im1 = axs[0].hist(X) im2, = axs[1].plot(np.arange(tps),[np.sum(X[:t])/(t+1) for t in range(tps)]) ims.append([im1, im2]) if display: ani = animation.ArtistAnimation(fig,ims, interval=50,blit=False) plt.show() return XEDIT : le
%matplotlib notebookvient du fait que je souhaite faire une animation sur Jupyter.
Connectez-vous ou Inscrivez-vous pour répondre.
Réponses
avec les même import que celui d'avant. Ceci me laisse penser que tout devrait fonctionner.