Changes in the standard Heatmap plot - symmetric bar colors, show only diagonal values, and column names at x,y axis ticks
I have a heatmap image (correlation between all matrix columns) and I'm straggling to preform all the changes below within the same image:
- bar colors should be symmetric around zero (e.g., correlation of 1 and -1 should be with the same color)
- change the correlation matrix to a diagonal matrix, since correlation values are symmetric - and show only upper matrix triangle (mask out the lower triangle )
- show the correlation values in every cell of the diagonal matrix
- x,y axis ticks - show the column names (instead of a serial number)
This is the code:
def generate_heatmap(X):
"""
Pearson Correlation Heatmap Plot
:return:
"""
print("Start Pearson Correlation Heatmap Plot .. ", datetime.now())
plt.figure(figsize=(10,8))
plt.title('Pearson Correlation of miRNAs', y=1.05, size=15)
# Correlation matrix for heatmap
corr = np.corrcoef(X.transpose())
plt.imshow(corr, cmap='BuPu', interpolation='nearest')
plt.colorbar()
plt.show()
Topic heatmap matplotlib correlation visualization python
Category Data Science