如果随时间推移源源不断接受新的数据,怎么将其动态地画出来,也即随时间更新呢?
使用matplotlib就能做到,一般用这个模板即可:
import matplotlib.pyplot as plt
my_fig, my_axe = plt.subplots()
my_line, = my_axe.plot([], [])
while True:
######### 其他代码(用来更新x_data和y_data) #########
my_line.set_xdata(x_data)
my_line.set_ydata(y_data)
my_axe.relim()
my_axe.autoscale_view()
my_fig.canvas.draw()
my_fig.canvas.flush_events()
plt.pause(0.001)
######### 其他代码 #########