A patch to Reinteract allows extensions to manipulate the output that goes to the notebook. refigure2 can take advantage of this ability to solve two annoyances.
This example illustrates two annoyances in the design of refigure2.
with figure() as f:1 plot([1,2,1]) f1
[<matplotlib.lines.Line2D object at 0x9f792ec>]2
Both of these problems could be fixed if extensions could manipulate the output that goes to Reinteract. To allow this, Owen Taylor wrote this patch for Reinteract. It has yet to be added to the trunk, so you will have to apply it yourself to get the new behavior. (If you're using git, you'll need the git am
command.) This isn't necessary — refigure2 will continue to work with the stock Reinteract. But you'll need it to get the following behavior.
When the patch is applied, refigure2 does two things differently:
rcParams['refigure.disableoutput'] = True
or passing the disable_output=True
keyword pair to figure()
. Note that print
statements still work.with figure(disable_output=True): plot([1,2,1]) print "Only the output I want!"
Only the output I want!
This second feature only disables the display of the return values; the plot commands still return the same values, so you can still do lines = plot(...)
.
If the prtining of output is not suppressed, old worksheets may display odd behavior, with two figure widgets output at the same time. The easiest way to fix this is to set the refigure.disableoutput
rc setting to True. This causes the figure returned by the old code to be ignored, leaving you with only the figure produced by the with
block. Personally, I recommend applying this setting in one of the global refigurerc
files (in the same directory as refigure2.py
or in ~/.matplotlib
) and then not worrying about it.
Robert Schroll, rschroll at gmail dot com