##// END OF EJS Templates
handle closed event loop in async script magics...
handle closed event loop in async script magics leave other problems with asyncio implementation for another PR

File last commit:

r22290:97a71f80
r27193:0fbbb2b5
Show More
Third Party Rich Output.ipynb
540 lines | 255.2 KiB | text/plain | TextLexer
/ examples / IPython Kernel / Third Party Rich Output.ipynb

Third Party Libraries With Rich Output¶

A number of third party libraries defined their own custom display logic. This gives their objcts rich output by default when used in the Notebook.

In [1]:
from IPython.display import display

Pandas¶

Pandas is a data analysis library for Python. Its DataFrame objects have an HTML table representation in the Notebook.

In [2]:
import pandas

Here is a small amount of stock data for APPL:

In [3]:
%%writefile data.csv
Date,Open,High,Low,Close,Volume,Adj Close
2012-06-01,569.16,590.00,548.50,584.00,14077000,581.50
2012-05-01,584.90,596.76,522.18,577.73,18827900,575.26
2012-04-02,601.83,644.00,555.00,583.98,28759100,581.48
2012-03-01,548.17,621.45,516.22,599.55,26486000,596.99
2012-02-01,458.41,547.61,453.98,542.44,22001000,540.12
2012-01-03,409.40,458.24,409.00,456.48,12949100,454.53
Writing data.csv

Read this as into a DataFrame:

In [4]:
df = pandas.read_csv('data.csv')

And view the HTML representation:

In [5]:
df
Out[5]:
Date Open High Low Close Volume Adj Close
0 2012-06-01 569.16 590.00 548.50 584.00 14077000 581.50
1 2012-05-01 584.90 596.76 522.18 577.73 18827900 575.26
2 2012-04-02 601.83 644.00 555.00 583.98 28759100 581.48
3 2012-03-01 548.17 621.45 516.22 599.55 26486000 596.99
4 2012-02-01 458.41 547.61 453.98 542.44 22001000 540.12
5 2012-01-03 409.40 458.24 409.00 456.48 12949100 454.53

SymPy¶

SymPy is a symbolic computing library for Python. Its equation objects have LaTeX representations that are rendered in the Notebook.

In [6]:
from sympy.interactive.printing import init_printing
init_printing(use_latex='mathjax')
In [7]:
from __future__ import division
import sympy as sym
from sympy import *
x, y, z = symbols("x y z")
k, m, n = symbols("k m n", integer=True)
f, g, h = map(Function, 'fgh')
In [8]:
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
Out[8]:
$$\frac{3 \pi}{2} + \frac{e^{i x}}{x^{2} + y}$$
In [9]:
a = 1/x + (x*sin(x) - 1)/x
a
Out[9]:
$$\frac{1}{x} \left(x \sin{\left (x \right )} - 1\right) + \frac{1}{x}$$
In [10]:
(1/cos(x)).series(x, 0, 6)
Out[10]:
$$1 + \frac{x^{2}}{2} + \frac{5 x^{4}}{24} + \mathcal{O}\left(x^{6}\right)$$

Vincent¶

Vincent is a visualization library that uses the Vega visualization grammar to build d3.js based visualizations in the Notebook and on http://nbviewer.ipython.org. Visualization objects in Vincetn have rich HTML and JavaSrcript representations.

In [11]:
import vincent
import pandas as pd
In [12]:
import pandas.io.data as web
import datetime
all_data = {}
date_start = datetime.datetime(2010, 1, 1)
date_end = datetime.datetime(2014, 1, 1)
for ticker in ['AAPL', 'IBM', 'YHOO', 'MSFT']:
    all_data[ticker] = web.DataReader(ticker, 'yahoo', date_start, date_end)
price = pd.DataFrame({tic: data['Adj Close']
                      for tic, data in all_data.items()})
In [13]:
vincent.initialize_notebook()
In [14]:
line = vincent.Line(price[['AAPL', 'IBM', 'YHOO', 'MSFT']], width=600, height=300)
line.axis_titles(x='Date', y='Price')
line.legend(title='Ticker')
display(line)