# Fluid everyday scientific computing ¶

In [1]:
%pylab inline

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].

In [2]:
import scipy.special as spec
x = linspace(0, 20, 200)
f, ax = plt.subplots()
for n in range(0,10,3):
plot(x, spec.jn(n, x), label=r'$J_%i(x)$' % n)
grid()
legend()
title('Bessel Functions')

Out[2]:
<matplotlib.text.Text at 0x42d6650>
In [3]:
%qtconsole


You can italicize, boldface

• build
• lists

and embed code meant for illustration instead of execution in Python:

def f(x):
"""a docstring"""
return x**2



or other languages:

if (i=0; i<n; i++) {
printf("hello %d\n", i);
x += 4;
}

Courtesy of MathJax, you can include mathematical expressions both inline: $e^{i\pi} + 1 = 0$ and displayed:

$$e^x=\sum_{i=0}^\infty \frac{1}{i!}x^i$$

## Rich displays: include anyting a browser can show¶

### Images¶

In [4]:
from IPython.display import Image
Image(filename='fig/logo.png')

Out[4]:
In [5]:
from IPython.display import HTML
HTML("""<table> <tr>
<tr><td>row 1, cell 1</td>
<td>row 1, cell 2</td></tr>
<tr><td>row 2, cell 1</td>
<td>row 2, cell 2</td></tr></table>""")

Out[5]:
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

In [6]:
import pandas
from IPython.display import display
pandas.core.format.set_printoptions(notebook_repr_html=True)

Date Open High Low Close Volume Adj Close
0 2013-02-12 200.01 200.74 199.02 200.04 2461800 200.04
1 2013-02-11 200.98 201.95 199.75 200.16 2944700 200.16
2 2013-02-08 199.97 202.09 199.68 201.68 2893300 201.68
3 2013-02-07 200.62 200.91 198.68 199.74 3076700 199.74
4 2013-02-06 200.39 201.29 199.56 201.02 3624200 201.02

### Video¶

In [7]:
from IPython.display import HTML
video_encoded = video.encode("base64")
video_tag = '<video controls alt="test" src="data:video/x-m4v;base64,{0}">'.format(video_encoded)
HTML(data=video_tag)

Out[7]:

And more exotic objects can also be displayed, as long as their representation supports the IPython display protocol.

For example, videos hosted externally on YouTube are easy to load (and writing a similar wrapper for other hosted content is trivial):

In [8]:
from IPython.display import YouTubeVideo

from IPython.display import HTML