I'm working on a new extension called refigure2, which is a spiritual successor to refigure. Both have the goal of embedding matplotlib plots in Reinteract, but they go about it in different ways. refigure2 uses a less idiosyncratic, though slightly more verbose, syntax, but it's most important feature is that it allows you to use existing plotting routines. This means it is compatible with the Basemap and mplot3d toolkits, as well as plotting routines you originally wrote for interactive use.
If you're just getting started, I recommend that you use refigure2, but if you're happy with the original extension there's no pressing reason to change.
refigure 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.
Other extensions embed matplotlib figures in Reinteract, but refigure has two notable features:
Version 0.4 works with matplotlib 0.99.1.1.
Version 0.3 contains several unrelated fixes:
A complete re-write of the first version, version 0.2 has the following advantages:
Let us not speak of this version.
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.)
Import the refigure module. For interactive work, I find it much easier to import it into the current namespace. refigure tries to avoid unnecessary namespace pollution.
from refigure import *
refigure does not import the numpy package, so you'll probably want to also do:
from numpy import *
Single pylab commands† can be given alone, to create simple plots:
Multiple pylab commands can be added together, so that they act on the same figure:
plot([1,2,3]) + ylim(0,5) + title('Plot title')
If the output from these functions is assigned to a variable, the result is not immediately plotted:
p = plot([1,2,3])
Additional commands can be added to this variable:
p += title('Plot title')
The plot is created like so:
refigure requires the use a GTK-based backend. If you use another backend by default, refigure will attempt to select an appropriate GTK backend. Should you wish to override this choice, include these commands before importing refigure:
from matplotlib import use
('GTK' or 'GTKCairo' may be used instead.)
More details can be found in the refigure tutorial. This tutorial is a Reinteract notebook in a gzipped tar file.
† 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.
ginput() is known not to work. Other functions may also fail — please report them.
Hovering over a PlotResult with a single command will not produce a tooltip. Instead, an exception is thrown on the console. Reinteract is able to survive this with no problems. Bizarrely, this seems to be because of a bug in inspect.isclass(), which thinks custom objects with a __getattr__ are classes. PlotResult has a working __getattr__ only when it has a single command.
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 refigure 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 refigure. As a work-around, rclocal can be used to adjust rcParams for the current figure only.
refigure is known to work with versions 0.98.1–0.99.1.1 of matplotlib. Please let me know if it works (or doesn't) with other versions of matplotlib. refigure will likely behave oddly with older versions of Reinteract, which had trouble properly marking which objects must be copied after each line.
Robert Schroll, rschroll at gmail dot com