如何通过在funcAnimation中传递参数来设置动画?

时间:2018-03-28 17:12:20

标签: python animation matplotlib

我必须制作一个时变的地理情节。

def animate(tindex, ax):
    summasel = summaout.isel(time = tindex)['pptrate'].drop('time').to_dataframe()
    summasel['hru_id2'] = summasel.index
    polydat2 = pd.merge(polydat, summasel)
    return (polydat2.plot(ax = ax, column = 'pptrate', cmap='viridis_r', scheme='quantiles'),)

fig, ax = plt.subplots()
a = ani.FuncAnimation(fig, animate, frames=40, fargs=(ax,), blit=True)
HTML(a.to_html5_video())

基本上,tindex是一个带范围的数字,比如1:10。对于每个tindexpolydat2.plot绘制一个变量为pptrate的shapefile。

如何将此范围传递给动画?可能我的语法都错了。

ERROR

~/anaconda3/lib/python3.6/selectors.py in _fileobj_to_fd(fileobj)
     37         except (AttributeError, TypeError, ValueError):
     38             raise ValueError("Invalid file object: "
---> 39                              "{!r}".format(fileobj)) from None
     40     if fd < 0:
     41         raise ValueError("Invalid file descriptor: {}".format(fd))

ValueError: Invalid file object: <_io.BufferedReader name=58>

This is what the plot looks like for one time instance enter image description here

打印(polydat2.head(2))

   OBJECTID    POI_ID PROD_UNIT  hru_elev   hru_id2    Y_Centroid  \
0         1  23336004       17a    1829.0  17000001  2.213807e+06   
1         2  23198872       17a    1902.0  17000002  2.214667e+06   

     X_Centroid    Basin_Area  seg_hru_id    Elev_Avg  Lon_Centro  Lat_Centro  \
0 -1.665466e+06  1.202901e+08    17001133  1890.24521  -116.20479    41.33139   
1 -1.555784e+06  1.248356e+08    17000804  1959.87124  -114.91219    41.53916   

                                            geometry   pptrate  
0  POLYGON ((-116.1746602138565 41.40417605744236...  0.000005  
1  (POLYGON ((-114.6447601321217 41.5900497438992...  0.000001  

修改

我尝试保存剧情而不是显示它。并直接使用编解码器(REF ISSUE)

a.save('./movie.mp4', writer='ffmpeg', codec='rawvideo')

NO LONGER 有上述错误。但我仍然得到一个空洞的情节。

0 个答案:

没有答案