In [1]:
%matplotlib inline
from string import letters
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white")
# Generate a large random dataset
rs = np.random.RandomState(33)
d = pd.DataFrame(data=rs.normal(size=(100, 26)),
columns=list(letters[:26]))
# Compute the correlation matrix
corr = d.corr()
# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)
# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3,
square=True, xticklabels=5, yticklabels=5,
linewidths=.5, cbar_kws={"shrink": .5}, ax=ax)
Out[1]:
In [2]:
from scipy.stats.stats import pearsonr
In [3]:
df_metadata = pd.read_csv('~/krse2011/db/krse2011_v5_metadata.csv')
In [5]:
params = df_metadata.columns[6:15]
In [6]:
df_pearson = pd.DataFrame(0.0, params, params)
In [7]:
for x in params:
for y in params:
df_pearson[x][y] = pearsonr(df_metadata[x], df_metadata[y])[0]
In [8]:
df_pearson
Out[8]:
In [9]:
# Generate a mask for the upper triangle
mask = np.zeros_like(df_pearson, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))
# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)
# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(df_pearson, mask=mask, cmap=cmap, vmax=.3,
square=True,
linewidths=.5, cbar_kws={"shrink": .5}, ax=ax)
Out[9]:
In [10]:
plt.savefig('pearson.pdf')
In [ ]: