import matplotlib.pyplot as plt from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT fig, ax = plt.subplots() ax.plot([1, 2, 3], [4, 5, 6]) toolbar = NavigationToolbar2QT(fig.canvas, None)
import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk from tkinter import * root = Tk() fig, ax = plt.subplots() ax.plot([1, 2, 3], [4, 5, 6]) toolbar = NavigationToolbar2Tk(fig.canvas, root) toolbar.update() canvas = FigureCanvasTkAgg(fig, master=root) canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) root.mainloop()In this example, we create a plot with one Axes instance and create a NavigationToolbar2Tk instance using fig.canvas and root as arguments. We also update the toolbar, create a FigureCanvasTkAgg instance, and pack it into the root window using Tkinter's pack() method. This creates a GUI-based window with the plot and a toolbar.