def createanim(data,start,skip,title=None,cmap='bone', ms_per_step=None):
"""
Return an animation of a single simulation run, each node
represented (via its node label) as pixel (i,j) in an MxN image.
So this will only be useful for grid graphs.
Args:
data: MxNxT array of voltage traces
start: first timestep to show
skip: timesteps to advance in each frame (higher -> faster)
title: figure title
cmap: matplotlib colormap (name OR object)
Return:
matplotlib animation object
"""
plt.ioff()
fig = plt.figure(figsize=fig_size)
titlefont = {'color' : 'black', 'size':12}
ax = plt.axes()#(xlim=(0, data.shape[1]), ylim=(data.shape[0]))
picture = ax.imshow(data[:, :, start], vmin=data.min(), vmax=data.max(),
interpolation="nearest", cmap=cmap)
plt.colorbar(picture,ax=ax,shrink=0.7)
def init():
picture.set_data(data[:,:,start])
return picture
def animate(i):
printprogress("animating frame",start+i*skip,data.shape[2])
if i*skip < data.shape[2]:
picture.set_data(data[:,:,start+i*skip])
t = " {}ms".format(start+i*skip * ms_per_step) if ms_per_step is not None else ""
plt.title(title+t,titlefont)
return picture
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=(data.shape[2]-start)/skip,interval=1, blit=False)
return anim
评论列表
文章目录