[IPython-User] Notebook: replot from axis object in subsequent cells

Matthias BUSSONNIER bussonniermatthias@gmail....
Sat Sep 15 06:16:00 CDT 2012


Hi Michael.


First, I suggest you use `subplots` with s , which return both the figure and the axes of each subplot.
And is a little more convenient than subplot. You could learn more with `subplots?`
You can then show the current sate of the figure at anytime with display(figure)

f , ax = subplots()
ax.plot(…)
display(f)
ax.plot(…)
display(f)


Or returning `f` at the end of you cell which will display it as output of the cell.
As you are writing a tutorial, just keep in mind that there is a slight difference between ending a cell with `display(f)` or `f`
as the first only display and the second return the figure.

Of course you can do the same with subplot (without s) as long as you use figure() and assign it to f before plotting.

`display` function  is specific to IPython, but difference between figures and axes are more a matplotlib issues in which i'm not an expert. 

We would be happy to see what are the use people make of the notebooks, so don't hesitate to share yours.
May I suggest you to have a look at nbconvert one of IPython organization repo on github[1], and also 
nbviewer[2] that might be useful for you , also Fernando did write a little blog post on how to embed notebook static view on blogs.[3] 

Cheers, 
-- 
Matthias

[1] https://github.com/ipython/nbconvert 
[2] http://nbviewer.ipython.org/
[3] http://blog.fperez.org/2012/09/blogging-with-ipython-notebook.html



Le 15 sept. 2012 à 09:17, Michael Waskom a écrit :

> Hi,
> 
> I'm working on converting some tutorials over from MATLAB into the Notebook. In these tutorials, frequently there will be some code to generate a plot, commentary on the plot, and then several small changes and replots (e.g. adding things in steps, changing the view in 3D plots, etc.)
> 
> Is there a way (using the matplotlib object-oriented interface) to replot an axis object in a subsequent cell, thus avoiding rewriting all of the common plotting code?  In other words something like:
> 
> In [12]: ax = subplot(111);  ax.plot(foo);
> 
> In [13]: replot(ax); ax.plot(bar)
> 
> Obviously in this toy example it doesn't save much, but for more complicated plots it could make things much more clean.
> 
> Thanks!
> Michael
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120915/941b394c/attachment.html 


More information about the IPython-User mailing list