Matplotlib is a MATLAB-like library that allows Python programmers to create images and animations. For example, you can easily draw a graphic representation of functions with Y (and maybe Z) values generated by numpy and scipy functions.
Matplotlib can also be interactive and handle events. The command
mpl_connect is used for connecting an event with a callback function.
The Backend Layer
Someone on the IRC has challenged me with questions on how to perform some operations when the window is closed. In addition, I want the window title to be other than the default, “Figure 1”.
Well, the layer that handles the main window is the backend layer,
To find what backend Matplotlib uses, you can add the line
The result may be something like:
This means that the backend used is ‘GtkAgg’.
With the function ‘dir’, I’ve found that the canvass has a function named
get_toplevel, and the returned value of
fig.canvass.get_toplevel() is an object of type
This object has the methods of a GTK window. So you can change its title with the ‘set_title
method. For example: fig.canvas.get_toplevel().set_title(‘Rubic Cube’)
You can tell your application what to do when the user closes the window, by calling its 'connect' method, with 'destroy' for first arguments.
More about Python FTK can be found at http://www.pygtk.org/pygtk2tutorial/index.html
Last but not least, you can specify the backend Matplotlib will use, by calling the ‘use’ method of matplotlib.
Note: This method should be called before importing ‘pyplot’.
Written with StackEdit.