matplotlib制作动画

来源:互联网 发布:霍启山评价郭晶晶 知乎 编辑:程序博客网 时间:2024/06/01 10:47
import matplotlib.pylab as pltimport numpy  as npimport matplotlib.animation as animationfig = plt.figure()ax = fig.add_subplot(111)n= 10x= np.random.rand(n)y= np.random.rand(n)z= np.random.rand(n)###^代表三角星,*代表五角星 +代表十字 ,b,g,b代表颜色circles,pentagon,dots = ax.plot(x,'bo',y,'g+',z,'b.')ax.set_ylim(0,1)plt.axis('off')#更新屏幕的内容def update(data):    circles.set_ydata(data[0])    pentagon.set_ydata(data[1])    return circles,pentagon#使用numpy生成随机数def generated():    while True: yield np.random.rand(2,n)anim = animation.FuncAnimation(fig,update,generated,interval=150)plt.show()
原创粉丝点击