Catch the sequel!

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.

0.4

A bug that prevented refigure from working with the current
version of matplotlib has been fixed. As always, please let me know
if refigure fails with your version of matplotlib.

The backend selection is more flexible. It will choose an
appropriate backend automatically if
rcParams['backend_fallback'] is
True (which it is by default).

This version contains experimental support for Jorn Baayen's printing
branch.

0.3

Version 0.3 contains several unrelated fixes:

savefig() now works. Just append it to some plotting commands, and a figure with those commands will be saved to the current working directory (or wherever you specify). This is very useful when making several figures to be combined in an animation.

close() also works. Commands before close() are executed; commands after it are not. No graph will be displayed in the worksheet. This is most useful in conjunction with savefig() when making a series of figures.

A new command, rclocal() adjusts rcParams for the current plot only. This helps to avoid some of the problems caused by the fact that one instance of rcParams is shared amongst all worksheets.

A strange bug, in which matplotlib's call of gtk.window_set_default_icon_from_file() occasionally causes a crash, has been worked around. The gtk module is monkey patched before matplotlib is loaded. In the long run, this can't be a good idea.

0.2

A complete re-write of the first version, version 0.2 has the following advantages:

Fewer random crashes.

Less memory leaked.

Marginally useful error handling.

0.1

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.)

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

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

use('GTKAgg')

('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.