使用matplotlib绘制动态图

主要使用animation.FuncAnimation来实现,其中的参数 func是更新图形的函数,frames是总共更新的次数,intit_func是图形开始使用的函数,
interval是更新的间隔时间(ms),blit决定是更新整张图的点(Flase)还是只更新变化的点(True)

import numpy as np
import matplotlib.pyplot as plt 
from matplotlib import animation

fig,ax = plt.subplots()

x = np.arange(0,10,0.1)
line, = ax.plot(x,np.sin(x))

def animat(i):
    line.set_ydata(np.sin(x+i/100))
    return line,
def initial():
    line.set_ydata(np.cos(x))
    return line,
ani = animation.FuncAnimation(fig=fig,func=animat,frames=100,init_func=initial,interval=20,blit=False)

plt.show()


你可能感兴趣的:(matplotlib)