当前位置:   article > 正文

python使用matplotlib.pyplot绘制动态图_matplotlib.pyplot做动态图流程

matplotlib.pyplot做动态图流程
  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import math
  4. import matplotlib.pyplot as plt
  5. import matplotlib.animation as antt
  6. fig = plt.figure()
  7. fig.handle=False
  8. img = fig.add_subplot(111)
  9. x=[]
  10. y=[]
  11. for i in range(0,100):
  12. x.append(i/100.0)
  13. y.append(math.sin(i/100.0))
  14. #a, = img.plot(np.array(x),'green')
  15. def dtt(data):
  16. global x,y
  17. for i in range(0,100):
  18. y[i]=math.sin(x[i])
  19. a,=img.plot(np.array(x),np.array(y),'green')
  20. #a.set_ydata(np.array(y))
  21. return a,
  22. def dong():
  23. global x
  24. while True:
  25. for i in range(0,100):
  26. x[i]+=0.5
  27. yield np.array(x)
  28. gif = antt.FuncAnimation(fig, dtt, dong, interval=10)
  29. plt.show()
  30. gif.save("picture.gif",writer="pillow",fps=3000)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/924329
推荐阅读
相关标签
  

闽ICP备14008679号