Plotly and Cufflinks

In [22]:
import numpy as np
import pandas as pd

%matplotlib inline
In [23]:
from plotly import __version__
import cufflinks as cf
In [24]:
# import js libraries
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
In [25]:
# connect js to notebook
init_notebook_mode(connected=True)
In [26]:
cf.go_offline()
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.
In [27]:
#create Data
df = pd.DataFrame(np.random.randn(100,4),
                  columns='A B C D'.split())

df.head()
Out[27]:
A B C D
0 1.426531 -0.349461 -1.117277 -1.180459
1 1.259944 -0.134409 0.937194 0.140856
2 -0.718913 -0.046177 -0.398886 0.584567
3 -0.576063 0.643790 1.488515 2.093161
4 1.232712 0.323555 0.559150 0.636520
In [28]:
df2 = pd.DataFrame({'Category':['A','B','C'],'Values':[32,43,50,]})
df2
Out[28]:
Category Values
0 A 32
1 B 43
2 C 50

Line Plot

In [29]:
df.iplot()
#     Click on legend to draw focus on specific element eg A & C

Scatter Plot

In [30]:
df.iplot(kind='scatter', x='A',y='B',mode='markers',size=20)

Bar Plot

In [31]:
df2.iplot(kind='bar',x='Category',y='Values')
In [32]:
# Aggregate function on the df bar with count
df.count().iplot(kind='bar')

Box Plot

In [33]:
df.iplot(kind='box')

3D Surface plot

In [34]:
df3 = pd.DataFrame({'x':[1,2,3,4,5],
                    'y':[10,24,32,20,9],
                    'z':[5,4,3,2,1]})
df3
Out[34]:
x y z
0 1 10 5
1 2 24 4
2 3 32 3
3 4 20 2
4 5 9 1
In [35]:
df3.iplot(kind='surface',colorscale='rdylbu')

Histogram

Overlapping Histograms

Turn column on / off by clicking on the legend

In [37]:
df.iplot(kind='hist',bins=30)

Spread type

In [38]:
df[['A','B']].iplot(kind='spread')

Bubble Plot

In [39]:
df.iplot(kind='bubble',x='A',y='B',size='C')

Scatter Matrix

In [40]:
df.scatter_matrix()