方法一:matplotlib循环添加数据
import numpy as npimport matplotlib.pyplot as plt"""
动态绘图方法一:
通过刷新图面的方法,每次循环在绘制新图画前,把当前绘图区的内容进行清空,
然后绘制新的图形
"""fig=plt.figure() #设置图面大小
plt1=plt.subplot(211) #设置绘图区域2行1列,第一个图区
plt2=plt.subplot(212)#设置绘图区域2行1列,第二个图区
plt1.axis([0, 100, 0, 1])
xa=[]
ya = []
pause_time=0.01 #动态刷新时间for i in range(50):
y = np.random.random()
ya.append(y) # 每迭代一次,将i放入y1中画出来
xa.append(i)
plt1.cla() # 清除键
plt1.plot(xa,ya)
plt.pause(pause_time)
![25af44911568b69403e9ddf963ab7886.png](https://i-blog.csdnimg.cn/blog_migrate/c67bd1a0ee98e06a3f6b9325a972aae2.jpeg)