Apr-15-2024, 09:09 AM
No worries, integrating matplotlib plots into Tkinter can be tricky
First, you need to make sure you have the FigureCanvasTkAgg and optionally NavigationToolbar2Tk imported from matplotlib.backends.backend_tkagg. These allow you to embed matplotlib figures into your Tkinter interface.
Give it a go and tweak the packing options if you need to adjust the layout.
First, you need to make sure you have the FigureCanvasTkAgg and optionally NavigationToolbar2Tk imported from matplotlib.backends.backend_tkagg. These allow you to embed matplotlib figures into your Tkinter interface.
# Assuming your fig and ax are already set up as you described: canvas = FigureCanvasTkAgg(fig, master=frame2) # Setting master to frame2 to display it there canvas.draw() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1) # Packing it into the GUI # If you want the navigation toolbar: toolbar = NavigationToolbar2Tk(canvas, frame2) toolbar.update() canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)Just paste this right after where you set up your fig and ax. This code places your plot within frame2 and fits it into the space you've specified. If you've already packed frame2 into your main window, everything should display as expected.
Give it a go and tweak the packing options if you need to adjust the layout.