2013-06-20 20 views
12

私はアニメーションにこの素晴らしい短いチュートリアルが見つかりました:私は、同じファッションのアニメーション関数imshow()プロットを生成カントしかしmatplotlib imshow():アニメーションを作成する方法は?

http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/

を。 は、私はいくつかの行置き換えることを試みた:

# First set up the figure, the axis, and the plot element we want to animate 
fig = plt.figure() 
ax = plt.axes(xlim=(0, 10), ylim=(0, 10)) 
#line, = ax.plot([], [], lw=2) 
a=np.random.random((5,5)) 
im=plt.imshow(a,interpolation='none') 
# initialization function: plot the background of each frame 
def init(): 
    im.set_data(np.random.random((5,5))) 
    return im 

# animation function. This is called sequentially 
def animate(i): 
    a=im.get_array() 
    a=a*np.exp(-0.001*i) # exponential decay of the values 
    im.set_array(a) 
    return im 

をしかし、私はあなたが私は、このランニングを得るのを助けることができ エラーに遭遇しますか? ありがとうございます。 最高、

+1

、あなたがあなたの質問になっているか、エラー含めることをお勧めします。 – tacaswell

答えて

12

は、あなたは非常に近いですが、1つのミスがあります - initanimateがアニメ化されているアーティストを含む反復可能オブジェクトを返す必要がありますが。そのため、Jakeのバージョンではline(これは単一行オブジェクト)ではなく、line,(実際はタプル)を返します。悲しいことに、ドキュメントはこれで明確ではありません!

あなたはこのようなあなたのバージョンを修正することができます:注意点として

# initialization function: plot the background of each frame 
def init(): 
    im.set_data(np.random.random((5,5))) 
    return [im] 

# animation function. This is called sequentially 
def animate(i): 
    a=im.get_array() 
    a=a*np.exp(-0.001*i) # exponential decay of the values 
    im.set_array(a) 
    return [im] 
+0

美しい! このコンマ表記は以前私を混乱させましたが、これは私を助けます! – user1805743

+0

ええ、私は '[list]'がもっとはっきりしている –

関連する問題