hcPlotting.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:synchrony 作者: cknd 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号