我尝试在一个循环中删除一个嵌入在tkinter中的matplotlib图形,并且每隔2秒就会被另一个matplotlib图形替换,但是这些图形不是逐个删除,而是一个接一个地叠加在一起,并且在循环结束时才会全部删除。
root = tk.Tk()
root.geometry("600x500")
fig, ax = plt.subplots(nrows = 3, ncols = 1, figsize = (6, 4))
t = np.linspace(0,10,len(X_EEG1[0]))
for data1, data2, data3, datay in zip(X_EEG1_ten, X_EEG2_ten, X_EMG_ten, y_ten):
ax[0].plot(t, data1, color = 'w', lw = 0.5)
ax[1].plot(t, data2, color = 'w', lw = 0.5)
ax[2].plot(t, data3, color = 'grey', lw = 0.5)
plt.tight_layout()
canvas = FigureCanvasTkAgg(fig, master = root)
canvas.draw()
canvas.get_tk_widget().pack()
root.update() # updating window to show figure
time.sleep(2) # wait 2 seconds
canvas.get_tk_widget().destroy() # destroy figure
root.update() # updating window to show destroyed figure
root.mainloop()
任何帮助都很感激,谢谢。
1条答案
按热度按时间j13ufse21#
我想出来了!👍🏻