import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([1, 2, 3], [4, 5, 6]) toolbar = plt.navigation_toolbar2(fm.canvas, fm.window) plt.show()
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar import matplotlib.pyplot as plt from PyQt5.QtWidgets import QApplication, QMainWindow fig, ax = plt.subplots() app = QApplication([]) win = QMainWindow() canvas = FigureCanvas(fig) win.setCentralWidget(canvas) toolbar = NavigationToolbar(canvas, win) win.addToolBar(toolbar) ax.plot([1, 2, 3], [4, 5, 6]) win.show() app.exec_()In this example, the NavigationToolbar2QT class from the PyQt5 backend_bases module is used to create a toolbar for a Matplotlib plot displayed in a PyQt5 GUI. The toolbar is added to the main window using the addToolBar method, and the plot is displayed in the FigureCanvas object associated with the window. Package/library: Matplotlib