我正在尝试创建一个gui,它将在收集数据时不断更新matplotlib图。我希望该图能够保留过去的5个数据点并在最近的数据点前面留出一些空白空间。
这是我脚本的一个极其简化的版本,它说明了我的问题所在:
import numpy as np
import pylab
import time
pylab.ion()
x1 = [0,1,2,3,4,5]
x2 = [5,6,7,8,9,10]
y1 = [5,6,7,8,7,8]
y2 =[8,7,6,5,4,3]
rate = 1
timer = 0
count = 0
while count <2:
if timer == 0:
pylab.plot(x1,y1)
pylab.show()
timer += rate
count += 1
time.sleep(1)
else:
pylab.plot(x2,y2)
pylab.draw()
timer += rate
count += 1
time.sleep(1)
我已经尝试过使用show(block = False)和其他一些东西。无论如何在代码继续时强制数字保持打开并且我可以使用命令来更新它?任何其他建议将不胜感激。
答案 0 :(得分:0)
以下序列对我有用..
请在此处更新图表 - 情节() - draw() - 而不是show()