-
-
Save danieltomasz/7323028b24054d27d3c8f42ffd0daad7 to your computer and use it in GitHub Desktop.
Create a triangular correlation plot (triangular heatmap)
This file contains 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
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