实时图表-我在这里做错了什么?

时间:2019-06-27 05:09:32

标签: python matplotlib livegraph

几天前,我开始学习matplotlib,并且编写了无效的代码。你能帮我吗。这是代码:

import matplotlib.pyplot as plt
from itertools import count
from matplotlib.animation import FuncAnimation
import random

index = count()
x1 = []
y1 = []

def animate(i):
    x1.append(next(index))
    y1.append(random.randint(-5, 12))
    plt.cla()
    plt.plot(x1, y1)    


FuncAnimation(plt.gcf(), animate, interval = 1000)

plt.tight_layout()
plt.show()

当我运行上面的代码时,它显示了一个空图,如下所示: enter image description here

谢谢

0 个答案:

没有答案
相关问题