Correlation Heatmap
In computer science, 0 is False and 1 is True. If we set the parameter dtype to Bool in np.zeros() we can get back False instead of 0.
import numpy as np
np.zeros(corr.shape, dtype=bool)
Now, this is where it gets complicated. np.triu_indices() returns two arrays of x and y coordinates where the coordinate combinations are the upper right triangle coordinates.
mask = np.zeros(corr.shape, dtype=bool)
np.triu_indices(len(mask))
We give a measure of number of rows, and we get back the coordinates for a square matrix with row and column size of this argument. We also set the array of true falses as a variable mask.
Now that we know how to get the correct parts of the array, we can set them to be true.
mask[np.triu_indices(len(mask))] = True
mask
Finally, use the argument mask to apply our mask!
sns.heatmap(corr,annot=True,mask=mask)
plt.show()
Source Code