The IPython Notebook is a front-end to the IPython interpreter that is meant to be a modern scientific notebook.
You can
notes
It's a great place for data exploration and logging your research progress. Let's learn about some of the features in detail.
The front-end relies on cells, which are just text boxes that can be designated as text or code. To edit a cell, you just double click on the text for that cell. To create a new cell, use the Insert
menu at the top of the page to insert a cell above or below the currently selected cell.
You can change the cell type using the drop-down menu to the left of the words Cell Toolbar
in the icon bar above. The cell type can be Code, Markdown, Raw Text, or a heading.
Code cells allow you to write and execute Python code in blocks. This is a bit nicer than the standard interpreter, where you have to do it line-by-line. This is especially helpful when you have to re-run some code -- you can just re-run the whole cell, instead of running each line independently. To run the code, use:
In the backend, code cells use the IPython interpreter, and thus has all of the same magic functions, tab complete, and extra help features that we have already seen.
print 8*11 + 16
print "demitri"
print "spam"*10
All the fancy IPython stuff is available here too:
ls
int?
%timeit range(1000)
Markdown is a human-readable markup format, similar to HTML but much more user-friendly. Markdown cells allow rich text formatting but will also display plain-text as expected.
Markdown basics: lists, markup and code
list item
list item
italics
bold
fixed-width font
Code examples:
def hello_ipython():
print "Hello IPython!"
I can also render equations in-line by enclosing latex in $'s:
$\alpha * \beta + \gamma^3$
$\int^6_0 x^2 dx$
You can include images and video, and even write HTML directly in the notebook:
from IPython.display import Image
Image(url='http://o.onionstatic.com/images/7/7954/original/700.hq.jpg', width=300)
from IPython.display import YouTubeVideo
YouTubeVideo('xEhaVhta7sI')
from IPython.display import HTML
HTML("<span style='font-family: \"Comic Sans MS\", cursive, sans-serif; font-size: 24pt;'>"
"Everyone loves comic sans!"
"</span>")
(Comes with IPython version >1.0)
A tool that converts the notebook file into another format, e.g., HTML, Latex, Markdown.
It's a command-line tool, so you run with:
ipython nbconvert --to FORMAT notebook-name.ipynb
Where FORMAT
can be html, latex, markdown, rtf, or slides.
A web service that lets you enter a link to a notebook (you can't upload the file, it has to be hosted somewhere), and it will render it as an HTML page at a permanent link for anyone to view!
For example: check this out
If you started with --pylab=inline, you're fine. If not, run this command:
%pylab inline
%pylab inline
Populating the interactive namespace from numpy and matplotlib
plot(np.random.random(size=(100)))
[<matplotlib.lines.Line2D at 0x106c9c210>]