Getting started with Jupyter

History

1988: Mathematica

https://www.wolfram.com/mathematica/

  • Created by Stephen Wolfram
  • Notebook interface designed by Theodore Gray
  • An all-in-one system: language (Wolfram Language), execution environment, scientific libraries

Key architectural details of Mathematica Notebooks:

  • Two parts to the system: kernel and front-end
  • The front-end sends the input to the kernel, which returns the result, which is displayed
  • Mathematica notebooks are objects that can be manipulated by Mathematica programs

2001: IPython

https://ipython.org/

Enhanced interactive environment that includes support for data visualization and facilities for distributed and parallel computation

2005: SageMath (previously Sage)

https://www.sagemath.org/

SageMath is a free open-source mathematics software system licensed under the GPL. It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, R and many more. Access their combined power through a common, Python-based language or directly via interfaces or wrappers.

Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.

Created by William Stein

2011: IPython Notebook

2014: Project Jupyter

https://jupyter.org/

Jupyter: Julia, Python, R

  • rendered by GitHub
  • support by VS Code python plugin
  • Google Colab
  • Kaggle

Installation

  • With pip:
    pip install jupyterlab
    

Starting

From the command line:

jupyter-notebook
jupyter-lab

On remote host:

ssh -L localhost:8888:localhost:8888 <server>

Jupyter interface

  • Jupyter Notebook
  • JupyterLab

Two modes: command mode and edit mode

Command mode keyboard shortcuts:

  • a : insert cell above
  • b : insert cell below
  • dd : delete selected cell
  • m : markdown
  • Enter: edit mode

Edit mode:

  • Tab : code completion or indent
  • Shift + Tab : tooltip
  • Esc : command mode

Markdown

Section headings:

  • # Heading 1
  • ## Heading 2
  • ## Heading 3
  • bold : **...** or __...__
  • italic : *...* or _..._
  • bold and italic : **_..._**

Lists:

  • unordered
      - item 1
      - item 2
  • ordered
      1. item 1
      2. item 2

$X_i^j$, see $$ a = \sum_i b_i \int_c^d f(x)\,\mathrm{d}x $$

$...$ for inline math, $$...$$ for displayed math \begin{align} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x - y - xz \\ \dot{z} & = -\beta z + xy \end{align}

Examples

In [1]:
2+2
Out[1]:
4
In [2]:
import numpy as np
import matplotlib.pyplot as plt
In [3]:
x = np.linspace(0, 20, 100)
y = np.sin(x)
s = np.abs(np.random.randn(x.shape[0])) * 100
In [4]:
plt.style.use('ggplot')
plt.scatter(x, y, c=y, s=s)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Sin')
plt.grid(True);

Widgets

In [5]:
import ipywidgets as widgets
In [6]:
def plot_Lissajous(nx, ny):
    N = 400
    t = np.linspace(0, 2 * np.pi, N)
    x = np.sin(nx * t)
    y = np.cos(ny * t)
    plt.plot(x, y)
    plt.ylim(-1.1, 1.1)
    plt.show()
In [7]:
wx = widgets.IntSlider(min=0, max=10, value=2, step=1, description="nx")
wy = widgets.IntSlider(min=0, max=10, value=3, step=1, description="ny", orientation='vertical')
out = widgets.interactive_output(plot_Lissajous, {'nx': wx, 'ny': wy})
ui = widgets.HBox([wy, widgets.VBox([out, wx])])
In [8]:
ui

Voilà

VoilĂ  transforms a Jupyter Notebook into a stand-alone web application

voila <path-to-notebook>

Deployment

https://mybinder.org/

Turn a Git repo into a collection of interactive notebooks

In [ ]: