我正在尝试刷新我的图形,因为另一个函数会生成新的点(x,y)。 Generator只是一个伪函数,但将作为我稍后编写的函数,它仅用于测试。 当我执行该类时,它将显示一个没有点的空白matplotlib图,并且不会随着生成器产生新点而刷新。
MyGUI()类:
style.use('fivethirtyeight')
points = []
def generator(points):
while True:
points.append([random.randint(-50, 50),random.randint(-50, 50)])
time.sleep(1)
return True
def animate(self,i):
#lines = [line.rstrip('\n') for line in points]
#print(lines)
print("animando\n")
xs = []
ys = []
for p in MyGUI.points:
print(p)
x = p[0]
y = p[1]
xs.append(x)
ys.append(y)
print(xs,ys)
self.ax1.clear()
self.ax1.plot(xs,ys,linestyle=':')
th = threading.Thread(target = generator, args =(points,))
th.start()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
a = animation.FuncAnimation(fig, animate,interval = 1000)
plt.show()
th.join()