Embedding a Matplotlib figure in a GTK+ window
We can now start to describe how to embed a Matplotlib Figure
into a GTK+ window as we walk through the code. We will present a simple example, and describe it step-by-step, highlighting the important parts of the code, in particular the GTK+ related ones.
Note again, we are not going to explain the GTK+ functionalities completely, and it is left to the reader to read further if he/she is interested.
Let's start:
import gtk from matplotlib.figure import Figure import numpy as np
These are the usual imports along with the gtk
module, which is required to access the GTK+ library functions. Once imported, the gtk
module also takes care of GTK+ environment initialization.
It is also common to find this type of import:
import pygtk pygtk.require('2.0') import gtk
It's useful to differentiate between multiple copies of PyGTK that might be installed on our system. The require()
function specifies that we need version 2.0, which covers all the versions...