##// END OF EJS Templates
s/choose/manual/g
s/choose/manual/g

File last commit:

r17506:fbd58505
r17923:876158e9
Show More
Third Party Rich Output.ipynb
522 lines | 256.9 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 [7]:
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 [9]:
import pandas

Here is a small amount of stock data for APPL:

In [10]:
%%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 [11]:
df = pandas.read_csv('data.csv')

And view the HTML representation:

In [12]:
df
Out[12]:
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

6 rows × 7 columns

SymPy¶

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

In [13]:
from sympy.interactive.printing import init_printing
init_printing(use_latex='mathjax')
In [14]:
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 [15]:
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
Out[15]:
$$\frac{3 \pi}{2} + \frac{e^{i x}}{x^{2} + y}$$
In [16]:
a = 1/x + (x*sin(x) - 1)/x
a
Out[16]:
$$\frac{1}{x} \left(x \sin{\left (x \right )} - 1\right) + \frac{1}{x}$$
In [17]:
(1/cos(x)).series(x, 0, 6)
Out[17]:
$$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 [1]:
import vincent
import pandas as pd
In [5]:
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 [8]:
vincent.initialize_notebook()
In [10]:
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)