Skip to content

Instantly share code, notes, and snippets.

@ychennay
Created May 18, 2019
Embed
What would you like to do?
import seaborn as sns
corr = X.corr()
# randomly pick 30 of the interest columns to drop to make the visualization more readable
drops = np.random.choice(X.filter(regex=('interest_1?[0-9]{2}')).columns,
size=30, replace=False)
corr = corr.loc[~corr.index.isin(drops)]
corr.drop(columns=drops, inplace=True)
# 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, center=0, annot=True,
square=True, linewidths=.5, cbar_kws={"shrink": .5})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment