I'm working on a reformulated version of refigure, innovatively named refigure2. refigure2 allows you to use your pre-existing plotting routines in Reinteract, with a cost of not that much more boilerplate. Check out the tutorial (tarred and gzipped notebook) for details.
Let me know your thoughts before I get too locked into the current syntax.
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.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.)
refigure requires that your matplotlib use a GTK-based backend. If you use another backend by default, run
from matplotlib import use
use('GTKAgg')
('GTK' or 'GTKCairo' may be used instead.)
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:
plot([1,2,3])
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:
p
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 version 0.98.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