Python动画图[关闭]

Python动画图[关闭],第1张

Python动画图[关闭]

Matplotlib是python的标准图形库,它带有相当不错的动画包。Jake
Vanderplas在这里有一个很好的教程。

从此链接获得的结果,如果要对正弦波进行动画处理,则可以使用以下方法:

import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib import animation# First set up the figure, the axis, and the plot element we want to animatefig = plt.figure()ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))line, = ax.plot([], [], lw=2)# initialization function: plot the background of each framedef init():    line.set_data([], [])    return line,# animation function.  This is called sequentiallydef animate(i):    x = np.linspace(0, 2, 1000)    y = np.sin(2 * np.pi * (x - 0.01 * i))    line.set_data(x, y)    return line,# call the animator.  blit=True means only re-draw the parts that have changed.anim = animation.FuncAnimation(fig, animate, init_func=init,frames=200, interval=20, blit=True)plt.show()

动画库每个间隔调用一次“动画”功能(在此示例中指定为20)。该功能应适当更新绘图。在这种情况下,它将使用set_data方法更新“线”,它是正弦波数据的数组。



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

原文地址: https://www.outofmemory.cn/zaji/5674931.html

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

发表评论

登录后才能评论

评论列表(0条)

保存