Embedding a Matplotlib figure in a Qt window
We are going to see how to embed a Matplotlib Figure
into a simple Qt window. We will first walk through the code and describe it, while presenting it as a whole at the end of the section (this presentation style will be used throughout the chapter).
Here is the beginning:
import sys
The module sys
contains information and functions used to interact with the Python interpreter. In this case, we need it to access the command-line arguments passed to the Python script.
from PyQt4 import QtGui
We import the PyQt4 submodule, QtGui
which contains the biggest part of the GUI classes, for example, all the basic GUI widgets are located in this module.
import numpy as np
The NumPy module is needed for our example graph.
from matplotlib.figure import Figure
Import the Figure
Matplotlib object: this is the backend-independent representation of our plot.
from matplotlib.backends.backend_qt4agg \ import FigureCanvasQTAgg as FigureCanvas
Here we import from the...