1 回答
TA贡献1846条经验 获得超7个赞
我找到了答案:
import random
from itertools import count
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from tkinter import *
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
x_vals = []
y_vals1 = []
y_vals2 = []
index = count()
root = Tk()
figId = plt.figure()
canvas = FigureCanvasTkAgg(figId, master=root)
canvas.get_tk_widget().pack()
canvas.draw()
def animate(i):
x_vals.append(next(index))
y_vals1.append(random.randint(0, 5))
y_vals2.append(random.randint(0, 5))
plt.cla()
plt.plot(x_vals, y_vals1)
plt.plot(x_vals, y_vals2)
ani = FuncAnimation(plt.gcf(), animate, interval=1000)
root.mainloop()
添加回答
举报