O'Reilly logo

Matplotlib for Python Developers by Sandro Tosi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required