I have to use the plot function from MNE library that returns a matplotlib figure of my plot.
As I'm builing an application under Tkinter, I want the figure to appear inside a window of my app.
I used this code. The plot is appearing both in the window of the app and in another matplotlib figure. The problem is that what appears in the app is static, it's just an instance of the matplotlib figure and I need an interactive one.
import tkinter as tk
from tkinter import ttk
from tkinter.filedialog import askopenfile
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from matplotlib import pyplot as plt
import mne
root = tk.Tk()
frame2 = tk.Frame(root)
frame2.pack(side= tk.LEFT,ipadx=500,ipady=350)
#Data path
file = 'C:\\Users\\...\chb01_01.edf'
#EDF to MNE Raw
data_raw = mne.io.read_raw_edf(file, preload=True)
but1 = tk.Button(frame2, text="plot",
command=lambda: time_plot(data_raw))
but1.pack()
def time_plot(data_raw):
f = data_raw.plot(duration=5, n_channels=23)
canvas = FigureCanvasTkAgg(f, frame2)
toolbarFrame = tk.Frame(frame2)
toolbarFrame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, toolbarFrame)
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
root.mainloop()
Any idea on how to solve the problem?