2013-08-02 28 views
5

Sorunun ne olduğunu bulmakta bana yardımcı olabilir misiniz? Neyin yanlış gittiğini bilmiyorum. img arasındaki tek grafikler sadece iyi çizilebilir, ancak animasyon modülü bir hata verir. Traceback diyor ki:Matplotlib Animasyon

Traceback (most recent call last): 
    File "/home/ckropla/workspace/TAMM/Sandkasten.py", line 33, in <module> 
    ani = animation.ArtistAnimation(fig, img, interval=20, blit=True,repeat_delay=0) 
    File "/home/ckropla/.pythonbrew/pythons/Python-3.3.1/lib/python3.3/site-packages/matplotlib/animation.py", line 818, in __init__ 
    TimedAnimation.__init__(self, fig, *args, **kwargs) 
    File "/home/ckropla/.pythonbrew/pythons/Python-3.3.1/lib/python3.3/site-packages/matplotlib/animation.py", line 762, in __init__ 
    *args, **kwargs) 
    File "/home/ckropla/.pythonbrew/pythons/Python-3.3.1/lib/python3.3/site-packages/matplotlib/animation.py", line 481, in __init__ 
    self._init_draw() 
    File "/home/ckropla/.pythonbrew/pythons/Python-3.3.1/lib/python3.3/site-packages/matplotlib/animation.py", line 824, in _init_draw 
    for artist in f: 
TypeError: 'AxesImage' object is not iterable 

Kodu:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.animation as animation 

def FUNCTION(p,r,t): 
    k_0,dx,c = p 
    x,y = r 
    z = np.exp(1j*(k_0[0]*np.meshgrid(x,y)[0]+k_0[1]*np.meshgrid(x,y)[1]-c*t))*np.exp(-((np.sqrt(np.meshgrid(x,y)[0]**2+np.meshgrid(x,y)[1]**2)-c*t)/(2*dx))**2)*(2/np.pi/dx**2)**(1/4) 
    z = abs(z) 
    #k,F = FFT((x-c*t),y) 
    return(x,y,z) 

#Parameter 
N = 500 
n = 20 
x = np.linspace(-10,10,N) 
y = np.linspace(-10,10,N) 
t = np.linspace(0,30,n) 
r=[x,y] 
k_0 = [1,1] 
dx = 1 
c = 1 
p = [k_0,dx,c] 

fig = plt.figure("Moving Wavepackage") 

Z = [] 
img = [] 
for i in range(n): 
    Z.append(FUNCTION(p,r,t[i])[2]) 
    img.append(plt.imshow(Z[i])) 

ani = animation.ArtistAnimation(fig, img, interval=20, blit=True,repeat_delay=0) 

plt.show() 

cevap

12

img içerisinde her eleman sanatçıların bir dizisi değil, tek sanatçı olması gerekir. img.append(plt.imshow(Z[i]))'u img.append([plt.imshow(Z[i])]) olarak değiştirirseniz, kodunuz düzgün çalışır.

+0

Çok teşekkür ederim! – throwaway17434