[IPython-User] what triggers a figure redraw / inline
Thu Feb 23 14:43:14 CST 2012
On Thu, Feb 23, 2012 at 11:11 AM, John Hunter <firstname.lastname@example.org> wrote:
> I am working on a notebook and want to build up a figure in stages to
> illustrate the effect of successive code blocks. After the first code cell,
> the figure is drawn and inlined, as expected. After the second, no figure
> is inserted, even if I try and force it to with "draw". How are you
> deciding whether to insert a figure or not, and is there a way to force the
> figure redraw inline?
The default behavior is to close the figures once they have been
created. But you have two ways to go about this:
Option #1. Since you're already keeping a reference to your figure (ps
- shame on you for still advertising the god-forsaken .subplot(111)
> fig = plt.figure(1, figsize=(5.5,5.5))
you can simply in your second cell return the figure as the very last
line of the second cell, or call display() on it. That is, replace
The difference of the second form is that it will work even if it's
not the last line, where as simply causing the fig repr to trigger a
display only happens if it's the last item. It also keeps a reference
to the figure since it produces an Out cell.
Option #2: you can change the closing behavior of the inline backend,
either for this notebook:
%config InlineBackend.close_figures = False
or permanently in your config file. At that point, figures remain
open and you're responsible for manually closing them, but this lets
you build a figure incrementally cell after cell. You can then
display it at the end either with display() or force all figures to
show with plt.show() at the end of a cell, just as if it was a script.
> BTW< I am using ipython from git HEAD and the new UI is *fantastic*. Very
> nice work, and very exciting!
Yes, it's looking great. If it weren't for the Strata/pydata/pycon
madness we might have been able to push a formal 0.13 release already
with all that, but it will need to wait a few weeks.
More information about the IPython-User