Jupyter Notebook can be used for:
The name Jupyter mixes Julia, Python and R, the first three languages targeted after iPython Notebook was reenginered to support different language processors (called kernels). This notebook is using the Python 3 kernel, as indicated in the top right corner.
Jupyter is a browser-based application that to edit and share interactive documents called notebooks.
As a first step, please take the User Interface Tour available from the Help menu above.
A notebook is made of text and code cells. You are reading a text cell, formatted using the Markdown syntax. To learn more about editing Markdown in Jupyter, read Working With Markdown Cells (local copy).
Code cells are written in the programming language supported by the running kernel. They produce output in the form of text, tables or graphics. This is a code cell:
In [ ]:
def fibonacci(n):
a, b = 0, 1
while n:
a, b = b, a + b
n -= 1
return a
fibonacci(100)
The label In [n] on the left indicates that is a code cell. If there's no n, the cell has not been executed. You can execute a code cell by selecting it and pressing the <ctrl><enter> keyboard combination. Please do it now and you'll see the 100th number in the Fibonacci sequence displayed in a new output cell, labeld Out [n], where n matches the number of the code cell that produced that output.
You can edit a code or text cell by clicking on it. Please edit the code cell above, changing the 100 argument in the fibonacci(100) function call to another number.
The content of a cell can be as simple as math expression like the one below. Use <shift><enter> to run it and select the next cell.
In [ ]:
2**100
In [2]:
%ls -la
To learn about the available magic commands, run %magic:
In [4]:
%magic
In [ ]:
%matplotlib inline
# use the "magic" command above once to configure inline graphs
import matplotlib.pyplot as plt
plt.bar(range(1, 7), [fibonacci(n) for n in range(1, 7)])
plt.xlabel('Fibonnacci numbers')
plt.show()
If you want to convey an idea instead of actual data, you may want to format a graph as in the style of a xkcd comic:
In [ ]:
with plt.xkcd():
plt.bar(range(1, 7), [fibonacci(n) for n in range(1, 7)])
plt.xlabel('vacation days')
plt.ylabel('ice cream gallons')
plt.show()
Attention: the Humor-Sans.ttf font needs to be installed for correct display of xkcd graphics. After installing the font, if you still get a missing font warning, run the cell below to clear the Jupyter font cache.
In [ ]:
import matplotlib as mpl
font_cache_path = mpl.get_cachedir() + '/fontList*.cache'
# uncomment the magic command below to actually clear the cache
# %rm $font_cache_path
The display module of the IPython API allows embedding several external media types into a notebook, including a Web page:
In [5]:
from IPython.display import IFrame
IFrame('https://en.wikipedia.org/wiki/Fibonacci_number', width='100%', height=400)
Out[5]:
In [ ]: