2017-05-18 7 views
0

私はパンダのデータフレームのリストを持っています。データフレームは、プロセス内の次のフレームを表しています。そのため、データフレームはすべて同じサイズと構造(同じ列とインデックス)です。私は、これらのデータフレームをアニメーション化し、MPEGムービーとしてアニメーションを保存する方法があるかどうか疑問に思っています。私は次の操作を実行しようとしていパンダのデータフレームのリストからアニメーションを生成する

は、しかし、すべての運を持っていなかった。

#X: a list of 1000 dataframe, all of same size 
fig = plt.figure() 
ax = fig.add_subplot(111) 

im = ax.imshow(X,interpolation='nearest') 


def update_img(n): 

    im.set_data(n.values) 
    return im 

animation = animation.FuncAnimation(fig,update_img, frames = X, interval=30) 

は、上記の最初のフレームで立ち往生。 mp4形式としてアニメーションを保存するには

+0

を使用することができます。 [mcve]を指定して、実行方法と場所、使用しているライブラリのバージョンを明確に記述することができます。 – ImportanceOfBeingErnest

答えて

0

、あなたは質問からコードが正常に動作している

import matplotlib.pyplot as plt 
import matplotlib.animation 
import numpy as np; np.random.seed(1) 
import pandas as pd 

X = [pd.DataFrame(np.random.rand(10,10)) for i in range(100)] 
fig = plt.figure() 
ax = fig.add_subplot(111) 

im = ax.imshow(X[0],interpolation='nearest') 

def update_img(n): 
    im.set_data(n.values) 

ani = matplotlib.animation.FuncAnimation(fig,update_img, frames = X, interval=30) 

FFwriter = matplotlib.animation.FFMpegWriter(fps=30)  
ani.save(__file__+".mp4",writer = FFwriter) 

plt.show() 
+0

ありがとう! "im = ax.imshow(X [0]、interpolation = 'nearest')"で、リストXを渡していました。これが問題の原因だと思います。再度、感謝します! – Alein

関連する問題