Skip to content

Instantly share code, notes, and snippets.

@lucananni93
Created November 1, 2017 15:49
Show Gist options
  • Save lucananni93/f2ff6fb2f2256575b9c3d546e526a7e1 to your computer and use it in GitHub Desktop.
Save lucananni93/f2ff6fb2f2256575b9c3d546e526a7e1 to your computer and use it in GitHub Desktop.
Create a triangular correlation plot (triangular heatmap)
import numpy as np
import seaborn as sns
from scipy.ndimage import rotate
def plot_heatmap_triu(m, shape=(10,10)):
"""
Plot a symmetric matrix as a triangluar heatmap.
- m: 2d ndarray of numpy (symmetric)
- shape of the final image (optional)
"""
rotated = rotate(np.triu(np.nan_to_num(m)), angle=45)
sns.plt.figure(figsize=shape)
sns.heatmap(rotated[:(int(rotated.shape[0]/2)),:],
xticklabels=False,
yticklabels=False,
cbar=False)
m = [[1, 2, 3],
[2, 5, 6],
[3, 6, 2]]
plot_heatmap_triu(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment