Skip to content

Instantly share code, notes, and snippets.

@danieltomasz
Forked from lucananni93/triangluar_heatmap.py
Created June 20, 2018 21:20
Show Gist options
  • Save danieltomasz/7323028b24054d27d3c8f42ffd0daad7 to your computer and use it in GitHub Desktop.
Save danieltomasz/7323028b24054d27d3c8f42ffd0daad7 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