2017-08-22 4 views
0

私はデータフレームフォーマット(xarray、Pandasに似ています)でデータを保存していますので、pcolormeshでアニメーション化します。matplotlibはmatplotlibのFuncAnimationコマンドを使用してデータフレーム内のデータをアニメーション化します

import sys 
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib.animation import FuncAnimation 

fig = plt.figure() 
ax1 = fig.add_subplot(1,1,1) 

def animate(i): 
    graph_data = mytest.TMP_P0_L1_GLL0[i] 
    ax1.pcolormesh(graph_data) 

FuncAnimation(plt,animate,frames=100) 

何らかの理由で動作しません(エラーはありませんが、図がアニメーション化していないことを示しています)。

データがレイアウトされている方法は、そのpcolormesh(mytest.TMP_P0_L1_GLL0 [0])が出力quadmesh、pcolormesh(mytest.TMP_P0_L1_GLL0 [1])が出力さ若干異なるquadmesh ...等である

ご協力いただきありがとうございます!

答えて

0

FuncAnimationの署名は、FuncAnimation(fig, func, ...)です。 pyplotモジュールの代わりに、最初の引数としてアニメーション化するFigureを指定する必要があります。

さらに、アニメーションクラスani = FuncAnimationへの参照を保持する必要があります。以下は、うまく動作する最小の例です。

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

class test(): 
    TMP_P0_L1_GLL0 = [np.random.rand(5,5) for i in range(100)] 

mytest = test() 

fig = plt.figure() 
ax1 = fig.add_subplot(1,1,1) 

def animate(i): 
    graph_data = mytest.TMP_P0_L1_GLL0[i] 
    ax1.pcolormesh(graph_data) 

ani = FuncAnimation(fig,animate,frames=100) 

plt.show() 
関連する問題