Created
September 15, 2017 14:26
-
-
Save p-m-m-c/1cc856eb5ea7be74f2e8dff9ba7afa19 to your computer and use it in GitHub Desktop.
Heatmap plot for df
This file contains hidden or 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
# 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