Corrplot demonstration

In [1]:
# some useful pylab imports for this notebook
%pylab inline
import pandas as pd
matplotlib.rcParams['figure.dpi'] = 120
matplotlib.rcParams['figure.figsize'] = (8,6)
Populating the interactive namespace from numpy and matplotlib
In [2]:
from biokit.viz import corrplot
In [3]:
# for debugging
# _ = reload(corrplot)

Let us create some dummy data set

In [24]:
import string
letters = string.ascii_uppercase[0:15]
df = pd.DataFrame(dict(( (k, np.random.random(10)+ord(k)-65) for k in letters)))
df = df.corr()
In [25]:
# if the input is not a square matrix or indices do not match 
# column names, correlation is computed on the fly
c = corrplot.Corrplot(df)
In [26]:
c.plot(colorbar=False, method='square', shrink=.9 ,rotation=45)
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [27]:
c.plot(method='text', fontsize=8, colorbar=False)
# only red to blue colormap is implemented so far
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [28]:
c.plot(method='color') # shrink not available
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [29]:
c.plot(method='pie', shrink=.9, grid=False)
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [30]:
c.plot(colorbar=False, method='circle', shrink=.9, lower='circle',
       label_color='red'  )
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [31]:
c.plot(colorbar=False, shrink=.8, upper='circle'  )
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [32]:
c.plot(colorbar=False, method='circle', shrink=.8, upper='circle' , 
       lower='square' )
# ignore the method if upper and lower are provided
# todo: option to set labels on diagonal
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [33]:
c.order(inplace=True)
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)
In [34]:
c.plot(method='circle')
/home/cokelaer/Work/github/biokit/biokit/viz/linkage.py:41: ClusterWarning: scipy.cluster: The symmetric non-negative hollow observation matrix looks suspiciously like an uncondensed distance matrix
  Y = hierarchy.linkage(D, method=method, metric=metric)