我是python的新手,我正在尝试制作一个应用程序,每隔5秒从IR传感器读取一些值,然后在两个子图中绘制这些值。到目前为止,我设法在一个真实语句中更新的情节中完成此操作。但我不能在使用Tkinter的App环境中这样做。我已设法绘制值但无法更新它们。你能帮助我吗?先谢谢你。
这是到目前为止的代码:
import numpy as np
import time
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib.animation as animation
temp_max = [25]*50
#window = tk.Tk()
#window.title("IR camera")
canvas_width = 300
canvas_height = 300
t1 = 120
t2 = 150
class App:
def __init__(self, master):
# Create a container
#frame = tk.Frame(master)
fig = Figure()
ax1 = fig.add_subplot(1,2,1)
ax2 = fig.add_subplot(1,2,2)
def plot_IR(self,master,i):
temp = np.round((t1-t2)*np.random.rand(64)+150, 2)
temp = np.transpose(temp.reshape((16,4)))
temp_max.append(temp.max())
del temp_max[0]
ymin = float(min(temp_max))-20
ymax = float(max(temp_max))+20
ax1.clear()
ax1.imshow(temp, interpolation='none', cmap="hot")
#Figure.colorbar(mappable='none', ax=ax1)
ax2.clear()
ax2.plot(temp_max)
ax2.set_ylim([ymin, ymax])
# #Botón de salida
# button = tk.Button(master, text='Quit', width=25, command=master.destroy)
# button.pack()
self.canvas = FigureCanvasTkAgg(fig, master=master)
self.canvas.get_tk_widget().pack()
self.canvas.draw()
#self.canvas.flush_events()
# frame.pack()
ani = animation.FuncAnimation(fig, plot_IR(self,master,1), init_func=temp_max, interval=20, blit=True)
#plot_IR(self,master)
#self.canvas.draw()
root = tk.Tk()
app = App(root)
root.mainloop()
我正在尝试在App中实现这一点,我已经搜索过,并且没有类似的问题解决了我的问题,要么是因为我不需要,要么我不明白如何在我的代码中实现它
谢谢!