[IPython-User] what triggers a figure redraw / inline

John Hunter jdh2358@gmail....
Thu Feb 23 15:31:56 CST 2012


On Thu, Feb 23, 2012 at 2:43 PM, Fernando Perez <fperez.net@gmail.com>wrote:

> Hey John,
>
> On Thu, Feb 23, 2012 at 11:11 AM, John Hunter <jdh2358@gmail.com> 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)
> syntax ;):
>


My bad -- I was translating this example

http://matplotlib.sourceforge.net/examples/axes_grid/scatter_hist.html

which may have pre-dated your much superior "plt.subplots".  Fixed now.
 Incidentally, I was thinking about presenting this example in a talk, and
was contemplating cutting-and-pasting the code into a standard ipython
terminal piece by piece to illustrate the effect of each axes divider call
(like an hbox or vbox for mpl figures, thanks JJ).  The for loops near the
end:

  for tl in axHistx.get_xticklabels():
      tl.set_visible(False)
  axHistx.set_yticks([0, 50, 100])

are not friendly to paste into ipython terminal shells because they do not
have the blank line after the indent.  Then I realized, aha, this is
precisely what the notebook excels at: building up a code example with
multi-line input in chunks.


> 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
> this:
>
> > plt.draw()
>
> with
>
> fig
>
> or
>
> display(fig)
>


This works great for my use case; I will play with the config parameters
later.  Thanks for the tips.


JDH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120223/a3a0a37e/attachment.html 


More information about the IPython-User mailing list