Skip to content

Instantly share code, notes, and snippets.

@jkmackie
Created September 22, 2022 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkmackie/2a5e455fd8072ccc81daeeee1eb6f18a to your computer and use it in GitHub Desktop.
Save jkmackie/2a5e455fd8072ccc81daeeee1eb6f18a to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
def annotate_w_xy_corr(x, y, **kwargs):
coef = np.corrcoef(x, y)[0][1]
label = r'corr = ' + str(round(coef,3))
ax = plt.gca()
ax.annotate(label, xy = (0.3, .07), xycoords = ax.transAxes, c='darkred') #size = 18
def pairplot_w_corr(df : pd.DataFrame):
sns.set(font_scale=1.2)
g = sns.PairGrid(df)
g.fig.subplots_adjust(top=0.93)
g.fig.suptitle(f'sample = {len(df)} points')
g.map_upper(sns.scatterplot)
g.map_upper(annotate_w_xy_corr)
g.map_lower(sns.scatterplot)
g.map_lower(annotate_w_xy_corr)
g.map_diag(sns.histplot, color='black')
pairplot_w_corr(df=samp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment