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:
withblock in order to operate on a single figure.
Keyboard control, custom rc files, and some bug fixes:
matplotlibrcfile, refigure2 will read rc settings from files named
refigurercin the same directory as
~/.matplotlib, and (if you are using the output patch) in the notebook directory, in that order.
figure.subplot.bottomon load. It does not respect settings for them in
matplotlibrc, but it does respect those settings in
refigurercfiles have the same format as a
matplotlibrcfile, with three additional settings:
refigure.printdpisets the DPI for printed figures when using the bitmap printing method. It defaults to 300.
refigure.keyboardcontrolsets whether the figure can grab keyboard focus when clicked and respond to keypress events. Defaults to True.
refigure.disableoutputsets whether output should be disabled by default inside
with figure()blocks. Defaults to False, meaning output is printed. (This is a change from 0.3, where output was not printed by default.) Output printing may still be adjusted on per-figure basis with the
from refigure2 import *doesn't pollute your namespace as much.
Several bug fixes and improvements:
rcParams['savefig.dpi'], so bump that up to get good results.
The locking mechanism has been fixed.
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
refigure2 is hosted at github, so if you want to hack it, you can clone the repository
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 figure() as f: plot([1,2,3]) ylim(0,5) title('Plot title') f
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
'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.
draw() don't work, but they aren't needed.
figure() works differently in refigure than in matplotlib; see the tutorial for details.
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 0.98.5.2–0.99.1.1 of matplotlib. Please let me know if it works (or doesn't) with other versions of matplotlib.
Robert Schroll, rschroll at gmail dot com