python - seaborn clustermap 不会重新排列注释数据

标签 python seaborn

我正在使用seaborn从矩阵绘制聚类图,并且我希望矩阵的值作为聚类图的注释。然而,虽然聚类图重新排列数据矩阵的行和列以形成聚类,但它不会对注释矩阵这样做。

这是我的代码:

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)

enter image description here

如图所示,注释与原始df相同,并且值没有按照图中的簇进行排列。

有什么方法可以正确地做到这一点吗?

最佳答案

您正在手动设置注释,只需使用

sns.clustermap(data=df, annot=True)  

enter image description here

关于python - seaborn clustermap 不会重新排列注释数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59502448/

相关文章:

python - 文本 Python 中的重复短语

python - 如何将 np.power 应用于数据框

python - 将非线性比例与 Seaborn 热图一起使用

python - 与 sns.barplot 一起绘制表格

python - 我在哪里可以找到有关 seaborn 中的联合绘图函数或 Python 中的 matplotlib 中此参数 'joint_kws' 的详细定义?

python - 在删除记录时更新干草堆索引,而无需重新索引整个数据库

python - cv2.solve无法返回最小二乘解

python - 未找到 Seaborn 模块 'histplot'

python - 使用坐标 python 列表的广度优先搜索

python - 如何创建具有多个子图的带状图