栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 面试经验 > 面试问答

使用Matplotlib动画更新x轴值

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用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的边框玩游戏,以便更新轴标签。



转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/640326.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号