2017-08-22 55 views
0

我以dataframe格式(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模块。

此外,您需要保留对动画类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() 
相关问题