Seaborn Correlation Coefficient on FacetGrid
To display the pearson correlation coefficient inside a Seaborn FacetGrid plot, you have to define a little corrfunc
function and then map it across the axes you want to have annotated:
from scipy import stats
import seaborn as sns
import matplotlib.pyplot as plt
def corrfunc(x, y, **kws):
r, _ = stats.pearsonr(x, y)
ax = plt.gca()
ax.annotate("r = {:.2f}".format(r),
xy=(.1, .9), xycoords=ax.transAxes)
g = sns.FacetGrid(df_tmp, col=c, hue=c, palette=my_palette, col_wrap=3, height=5)
g.map(plt.scatter, x, y, alpha=.7, s=3)
g.map(corrfunc, x, y)