Corrplot demonstration


In [27]:
# some useful pylab imports for this notebook
%pylab inline
import pandas as pd
matplotlib.rcParams['figure.dpi'] = 120
matplotlib.rcParams['figure.figsize'] = (6,5)


Populating the interactive namespace from numpy and matplotlib

In [28]:
from sequana.viz import Corrplot

Let us create some dummy data set


In [29]:
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 [30]:
# if the input is not a square matrix or indices do not match 
# column names, correlation is computed on the fly
c = Corrplot(df)

In [31]:
c.plot(colorbar=False, method='square', shrink=.9 ,rotation=45)



In [32]:
c.plot(method='text', fontsize=8, colorbar=False)
# only red to blue colormap is implemented so far



In [33]:
c.plot(method='color') # shrink not available


Out[33]:
<matplotlib.colorbar.Colorbar at 0x7ff0c14f4dd8>

In [34]:
c.plot(method='pie', shrink=.9, grid=False)


Out[34]:
<matplotlib.colorbar.Colorbar at 0x7ff0c12affd0>

In [35]:
c.plot(colorbar=False, method='circle', shrink=.9, lower='circle',
       label_color='red'  )



In [36]:
c.plot(colorbar=False, shrink=.8, upper='circle'  )



In [37]:
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



In [38]:
c.order(inplace=True)

In [39]:
c.plot(method='circle')


Out[39]:
<matplotlib.colorbar.Colorbar at 0x7ff0c027fdd8>

In [40]:
# with ellipses, rotation of the patches helps to see the different patterns

In [41]:
c.plot(cmap=('orange', 'white', 'green'))


Out[41]:
<matplotlib.colorbar.Colorbar at 0x7ff0c1131eb8>

In [42]:
# More tuning with shrink and fontsizes

In [43]:
df = [[1,.5,-.5],[.5,1,-.1],[-.5,-.1,1]]
c = Corrplot(df)
c.plot(method='square', cmap=('red', 'white', 'blue'), 
       fontsize=30, shrink=1, colorbar=False)


subplot and axes


In [44]:
fig = plt.figure()
fig.subplots_adjust(left=0.2, wspace=0.6)
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)

import numpy as np
c = Corrplot(np.random.rand(10,10))
c.plot(fig=fig, ax=ax3, colorbar=True, cmap='copper', method='rectangle')
c.plot(fig=fig, ax=ax4, colorbar=True, cmap='jet', method='color')
c.plot(fig=fig, ax=ax2, colorbar=True, cmap='hot', method='ellipse')
c.plot(fig=fig, ax=ax1, colorbar=True, method='pie')


Out[44]:
<matplotlib.colorbar.Colorbar at 0x7ff0c026d4a8>

In [ ]:


In [ ]: