1

I'm building a GUI under tkinter and I need to plot EEG signals within my app page. After importing everything needed, I created the canvas as follows:

class StartPage(tk.Frame):

 def __init__(self, parent, controller):
    tk.Frame.__init__(self,parent)
    label = tk.Label(self, text=("Time Representation"), font=LARGE_FONT)
    label.pack(pady=10,padx=10)

    f = plt.figure()
    a = f.add_subplot(111)

    canvas = FigureCanvasTkAgg(f, self)
    canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)

    toolbar = NavigationToolbar2Tk(canvas, self)
    toolbar.update()
    canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)

    button1 = ttk.Button(self, text="plot",
                        command=lambda: time_plot())
    button1.pack()

    def time_plot()

The problem is that when I plot my data, another figure pops open and the page of my app appears with a blank graph.

Here's the ploting part of my function:

        def time_plot():
        ....
        a.set_xticks(np.arange(t_window))
        lines = LineCollection(segs, offsets=offsets, transOffset=None)
        a.add_collection(lines)

        a.set_yticks(ticklocs)
        a.set_yticklabels(ch_names)
        a.set_xlabel('Time (s)')

        plt.tight_layout()
        plt.show()

        canvas.draw()

As I'm new to both python and tkinter, I don't know where the problem is to make the plot appear within the app. I think that it is caused by the plt.show() but I don't know how to fix it either.

1 Answer 1

1

I could finally solve it on my own. I have commented these two lines and my plot is appearing inside the canvas:

#plt.tight_layout()
#plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.