Created
September 22, 2022 15:34
-
-
Save jkmackie/2a5e455fd8072ccc81daeeee1eb6f18a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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