## Jupyter at Bryn Mawr College

Public notebooks: /services/public/dblank

# 1. Telling Stories with Jupyter Notebooks¶

### Doug Blank Bryn Mawr College Department of Computer Science

For telling stories in Digital Humanities, Mathematics, Sciences, Art, and Computing.

## 1.1 Markdown¶

Simple formatting including bold, italics, strike through, lists, links, etc.

1. Thing one
2. Thing two
3. Thing three

This is a quote from an important person. - Me

### 1.1.1 HTML¶

Can mix in HTML in the Markdown.

### 1.1.2 Images¶

Including images:

### 1.1.3 Equations¶

#### 1.1.3.1 Maxwell's Equations¶

\begin{align} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{align}

#### 1.1.3.2 Probability¶

The probability of getting $k$ heads when flipping $n$ coins:

\begin{equation*} P(E) = {n \choose k} p^k (1-p)^{ n-k} \end{equation*}

## Computing¶

Biology simulation.

In [23]:
%%simulation

#right turns
0 ***** -> forward(1)    1
1 ***** -> turnRight(90) 2
2 ***** -> forward(1)    3
3 ***** -> turnRight(90) 4
4 ***** -> forward(1)    5
5 ***** -> turnRight(90) 6
6 ***** -> forward(2)    7
7 ***** -> turnRight(90) 8
8 ***** -> forward(2)    9
9 ***** -> turnRight(90)  10
10 ***** -> forward(2)    11
11 ***** -> turnRight(90) 12
12 ***** -> forward(3)    13
13 ***** -> turnRight(90) 14
14 ***** -> forward(3)    15

#left turns
15 ***** -> turnLeft(90)  16
16 ***** -> forward(1)    17
17 ***** -> turnLeft(90)  18
18 ***** -> forward(4)    19
19 ***** -> turnLeft(90)  20
20 ***** -> forward(4)    21
21 ***** -> turnLeft(90)  22
22 ***** -> forward(4)    23
23 ***** -> turnLeft(90)  24
24 ***** -> forward(5)    25
25 ***** -> turnLeft(90)  26
26 ***** -> forward(5)    27
27 ***** -> turnLeft(90)  28
28 ***** -> forward(5)    29
29 ***** -> turnLeft(90)  30
30 ***** -> forward(6)    31
31 ***** -> turnLeft(90)  32
32 ***** -> forward(6)    33
33 ***** -> turnLeft(90)  34
34 ***** -> forward(6)    35

#right turns
35 ***** -> turnRight(90) 36
36 ***** -> forward(1)    37
37 ***** -> turnRight(90) 38
38 ***** -> forward(7)    39
39 ***** -> turnRight(90) 40
40 ***** -> forward(7)    41
41 ***** -> turnRight(90) 42
42 ***** -> forward(7)    43
43 ***** -> turnRight(90) 44
44 ***** -> forward(8)    45
45 ***** -> turnRight(90) 46
46 ***** -> forward(8)    47
47 ***** -> turnRight(90) 48
48 ***** -> forward(8)    49
49 ***** -> turnRight(90) 50
50 ***** -> forward(9)    51
51 ***** -> turnRight(90) 52
52 ***** -> forward(9)    53
53 ***** -> turnRight(90) 54
54 ***** -> forward(9)    55
55 ***** -> turnRight(90) 56
56 ***** -> forward(8)    57
57 ***** -> forward(2)    58
58 ***** -> turnRight(90) 59
59 ***** -> forward(8)    60
60 ***** -> forward(4)    61
61 ***** -> turnRight(90) 62
62 ***** -> forward(9)    63
63 ***** -> forward(3)    64
64 ***** -> turnRight(90) 65
65 ***** -> forward(8)    66
66 ***** -> forward(5)    67
67 ***** -> turnRight(90) 68
68 ***** -> forward(9)    69
69 ***** -> forward(4)    70
70 ***** -> turnRight(90) 71
71 ***** -> forward(5)    72

#turn left
72 ***** -> turnLeft(90)  73
73 ***** -> forward(9)    74
74 ***** -> turnLeft(90)  75
75 ***** -> forward(9)    76
76 ***** -> forward(9)    77
77 ***** -> forward(1)    1


## Computing and Visualization¶

In [17]:
import pandas as pd
import numpy as np
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
columns=['A', 'B', 'C', 'D'])
df = df.cumsum()

In [16]:
%matplotlib inline
import matplotlib.pyplot as plt

In [22]:
plt.figure()
df.plot()
plt.legend(loc='best')

Out[22]:
<matplotlib.legend.Legend at 0x7ff6231876a0>
<matplotlib.figure.Figure at 0x7ff623190fd0>