使用Matplotlib动画更新x轴值

使用Matplotlib动画更新x轴值,第1张

使用Matplotlib动画更新x轴值

如果你 没有 需要阻击

import matplotlib.pylab as pltimport matplotlib.animation as animationimport numpy as np#create image with format (time,x,y)image = np.random.rand(100,10,10)#setup figurefig = plt.figure()ax1 = fig.add_subplot(1,2,1)ax2 = fig.add_subplot(1,2,2)#set up viewing window (in this case the 25 most recent values)repeat_length = (np.shape(image)[0]+1)/4ax2.set_xlim([0,repeat_length])#ax2.autoscale_view()ax2.set_ylim([np.amin(image[:,5,5]),np.amax(image[:,5,5])])#set up list of images for animationim = ax1.imshow(image[0,:,:])im2, = ax2.plot([], [], color=(0,0,1))def func(n):    im.set_data(image[n,:,:])    im2.set_xdata(np.arange(n))    im2.set_ydata(image[0:n, 5, 5])    if n>repeat_length:        lim = ax2.set_xlim(n-repeat_length, n)    else:        # makes it look ok when the animation loops        lim = ax2.set_xlim(0, repeat_length)    return im, im2ani = animation.FuncAnimation(fig, func, frames=image.shape[0], interval=30, blit=False)plt.show()

将工作。

如果需要运行得更快,则需要使用用于blitting的边框玩游戏,以便更新轴标签。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5646130.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存