Skip to content

Instantly share code, notes, and snippets.

@p-m-m-c
Created September 15, 2017 14:26
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 p-m-m-c/1cc856eb5ea7be74f2e8dff9ba7afa19 to your computer and use it in GitHub Desktop.
Save p-m-m-c/1cc856eb5ea7be74f2e8dff9ba7afa19 to your computer and use it in GitHub Desktop.
Heatmap plot for df
# INPUT: pandas DataFrame
# Compute the correlation matrix
corr = df.corr()
# 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=(15, 12))
# 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,
square=True, linewidths=.8, cbar_kws={"shrink": .5})
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment