matplotlib学习笔记【10】:动画展示
程序员文章站
2024-03-26 08:12:29
...
1. 代码
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x + i/10.0)) # update the data
return line,
# Init only required for blitting to give a clean slate.
def init():
line.set_ydata(np.sin(x))
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
# blit=True dose not work on Mac, set blit=False
# interval= update frequency
"""
func代表他参数改变的函数,frames是帧数,init_func是它初始的状态,
interval是每20秒更新一次,blit是指是否按照图像的更新去进行动画展示。Flase代表以更新去展示
"""
ani = animation.FuncAnimation(fig=fig, func=animate, frames=100, init_func=init,
interval=20, blit=False)
# save the animation as an mp4. This requires ffmpeg or mencoder to be
# installed. The extra_args ensure that the x264 codec is used, so that
# the video can be embedded in html5. You may need to adjust this for
# your system: for more information, see
# http://matplotlib.sourceforge.net/api/animation_api.html
# anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
plt.show()
2. 运行结果
自己运行以下就知道了。动态的不好展示
推荐阅读
-
matplotlib学习笔记【10】:动画展示
-
ReactNative学习笔记四之动画篇
-
概率论与数理统计及其应用学习笔记1(numpy+matplotlib)
-
Xcode9学习笔记58 - 使用CATransaction Push制作动画(从左往右飘进图片)
-
Xcode9学习笔记54 - 使用CATransaction Reveal制作动画
-
寒假学习笔记10
-
Log4j.1.2.14 学习笔记【10月4日更新】 博客分类: JavaLog4j Log4j日志
-
h5学习笔记之CSS3过渡与CSS3动画
-
Tensorflow学习笔记:CNN篇(10)——Finetuning,猫狗大战,VGGNet的重新针对训练
-
[NLP学习笔记-Task10] Transformer + BERT