In this recipe, we will learn how to embed a Matplotlib canvas in a Qt GUI application.
Embedding Matplotlib in to a Qt GUI application
Getting ready
Import the required libraries:
import sys
import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.qt_compat import QtCore, QtWidgets, is_pyqt5,
QtGui
if is_pyqt5():
from matplotlib.backends.backend_qt5agg import (
FigureCanvas, NavigationToolbar2QT
as NavigationToolbar)
else:
from matplotlib.backends.backend_qt4agg import (
FigureCanvas, NavigationToolbar2QT
as NavigationToolbar)