refigure2 is an extension for Reinteract that allows the embedding of matplotlib plots. It does so with a syntax reminiscent of pylab, matplotlib's procedural (MATLAB™-like) interface. refigure2 is a spiritual successor to refigure, though the two share little code and less syntax.


Other extensions embed matplotlib figures in Reinteract, but refigure2 has three notable features:

  1. Entire figures are embedded in the notebook. This allows the creation of figures with multiple axes. Additionally, the inclusion of the figure's toolbar allows interactive panning, zooming, and more.
  2. Most of the pylab commands are available. They are grouped together within a with block in order to operate on a single figure.
  3. Existing plotting routines based on matplotlib can be used unchanged, provided that they don't insist on creating their own figures for plotting. This means that refigure2 is compatible with toolkits like Basemap and mplot3d. See the refigure2 gallery [.tar.gz|.zip] for examples.

What's New


Keyboard control, custom rc files, and some bug fixes:


Several bug fixes and improvements:


The locking mechanism has been fixed.


Initial release.



Getting It

Download the single .py file. Place it in your ~/.reinteract/modules folder, which you may need to create. (It can also go in the reinteract/lib folder of your Reinteract installation, or somewhere else on your sys.path.)

refigure2 is hosted at github, so if you want to hack it, you can clone the repository git://

Using It

Import the refigure2 module. For interactive work, I find it much easier to import it into the current namespace. refigure2 tries to avoid unnecessary namespace pollution.

from refigure2 import *

You'll almost always want numpy as well:

from numpy import *

Single pylab commands can be given alone, to create simple plots:


Multiple pylab commands can be grouped together in a with block.

with figure() as f:
    title('Plot title')

refigure2 requires the use a GTK-based backend. If you use another backend by default, refigure2 will attempt to select an appropriate GTK backend. Should you wish to override this choice, include these commands before importing refigure2:

from matplotlib import use

('GTK' or 'GTKCairo' may be used instead.)

More details can be found in the refigure2 tutorial [.tar.gz|.zip].

Most of the pylab commands work in refigure. ginput() is known not to work; others may also fail. show() and draw() don't work, but they aren't needed. figure() works differently in refigure than in matplotlib; see the tutorial for details.

Known Issues

Bugs will be tracked on the github issue tracker.

ginput() is known not to work. Other functions may also fail — please report them.

Settings made in rcParams leak between open worksheets, even if they're not part of the same notebook. This is because modules are singletons in Python. Therefore, all open worksheets share the same refigure2 object, which contains rcParams. Reinteract must be completely closed to reset these settings (or you can manually tweak rcParams). I don't know if this is fixable within refigure2. As a work-around, rclocal can be used to adjust rcParams for the current figure only.

refigure2 is known to work with versions– of matplotlib. Please let me know if it works (or doesn't) with other versions of matplotlib.

Robert Schroll, rschroll at gmail dot com