Reputation: 83
I am using seaborn to plot a clustermap from a matrix, and I want the values of the matrix to be the annotations of the clustermap. However, while the clustermap rearranges rows and columns of the data matrix to form clusters, it does not do so for the annotation matrix.
Here is my code:
data = np.random.rand(10,5)
print (data)
[[0.62906695 0.41046601 0.04774079 0.98012573 0.79686483]
[0.1618218 0.70365808 0.53644302 0.68291708 0.95152119]
[0.901431 0.19378611 0.33176554 0.00219459 0.92936903]
[0.1575622 0.37749714 0.88975381 0.16945422 0.23790588]
[0.06837024 0.49287138 0.60866541 0.80563271 0.38924653]
[0.13671484 0.11410341 0.14604541 0.49899899 0.82850949]
[0.90237875 0.23954254 0.41614074 0.11811778 0.26017433]
[0.27881206 0.09321617 0.62520404 0.10796313 0.12266986]
[0.27606845 0.8479972 0.86467503 0.19660883 0.11909075]
[0.64211049 0.61860723 0.70426254 0.24465052 0.17614033]]
df = pd.DataFrame(data, columns=['A','B','C','D','E']).corr()
df
A B C D E
A 1.000000 -0.229103 -0.353145 -0.360782 0.084730
B -0.229103 1.000000 0.498165 0.256117 -0.162689
C -0.353145 0.498165 1.000000 -0.443952 -0.727170
D -0.360782 0.256117 -0.443952 1.000000 0.448025
E 0.084730 -0.162689 -0.727170 0.448025 1.000000
sns.clustermap(data=df, annot=df)
As you can see in the figure, the annotations are the same with the original df
and the values have not been arranged according to the clusters in the figure.
Is there any way I can do this correctly?
Upvotes: 1
Views: 1083
Reputation: 2110
You are manually setting the annotations, just use
sns.clustermap(data=df, annot=True)
Upvotes: 3