Skip to content

Instantly share code, notes, and snippets.

@javadnoorb
Last active May 22, 2018 20:38
Show Gist options
  • Save javadnoorb/821974c5732c4c87db6edf6e5decc7ce to your computer and use it in GitHub Desktop.
Save javadnoorb/821974c5732c4c87db6edf6e5decc7ce to your computer and use it in GitHub Desktop.
function to create lower traiangle pairplots from a dataframe (tmp) and annotate it with correlation values
import seaborn as sns
import pandas as pd
def make_lower_pairplot(tmp, plot_unit_line=True, corrs_method = 'spearman'):
try:
g = sns.pairplot(tmp)
except FloatingPointError as e:
warnings.warn(e.args)
return tmp
g.map_upper(lambda x, y, **kwargs: pl.gca().set_visible(False));
if plot_unit_line:
g.map_lower(lambda x, y, **kwargs: pl.plot([0,1], [0,1], '--r'))
for i in range(g.axes.shape[0]):
g.axes[i, i].set_visible(False)
g.diag_axes[i].set_visible(False)
corrs = tmp.corr(method=corrs_method)
for i in range(g.axes.shape[0]):
for j in range(i):
ax = g.axes[i ,j]
ax.text(0.05, 1, "r = {:.2f}".format(corrs.iloc[i,j]), color='red', transform=ax.transAxes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment