ClusterMapSeaborn屏蔽矩阵的上对角线,固定每个“单元”的大小,并删除链接每个单元的线

2024-09-27 21:31:35 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我绘制了相关的聚类图,我发现了一些挫折,如果你们能帮我的话。你知道吗

import seaborn as sns 
import matplotlib.pyplot as plt 
import numpy as np 

grafico_correlacao_renda_variavel_long_biased = sns.clustermap(correlacao_renda_variavel_long_biased, linewidths=.5,figsize=(40,40),annot= True,mask=mask,annot_kws={"size": 25})
plt.setp(grafico_correlacao_renda_variavel_long_biased.ax_heatmap.get_yticklabels(), rotation=0,fontsize=45)
plt.setp(grafico_correlacao_renda_variavel_long_biased.ax_heatmap.get_xticklabels(), rotation=90,fontsize=45)
grafico_correlacao_renda_variavel_long_biased.fig.suptitle('Renda Variável Long Biased',fontsize=100) 
grafico_correlacao_renda_variavel_long_biased.savefig('teste.pdf')
plt.show() 

enter image description here

那么我的问题是什么:

1)顶部和底部仅显示其大小的一半,我不知道如何修复它,我尝试缩小大小,但它没有做任何事情。你知道吗

2)虽然我希望地图是群集的,但我不希望地图外的线连接每个“单元”,有没有办法删除它?你知道吗

3)我只想显示对角线矩阵的下半部分,但当我应用遮罩时,它会在矩阵上给我几个空格

我的面具:面具=类np.zeros\u(correlacao\u renda\u variavel\u long\u biasted,数据类型)=np.布尔) 遮罩[np.triu\u索引\u来自(掩码)]=真

enter image description here


Tags: importasnppltmasklongsnsbiased
1条回答
网友
1楼 · 发布于 2024-09-27 21:31:35

问题似乎是clustermap将掩码与数据一起排列。我的解决方案是运行clustermap两次:一次找出排列,以便创建一个掩码,这样一旦你将排列应用到它,你就可以恢复你真正想要的掩码。然后,用这个新掩码运行clustermap。即:

g = grafico_correlacao_renda_variavel_long_biased #for conciseness
# apply the inverse permutation to the mask
mask = mask[np.argsort(g.dendrogram_row.reordered_ind),:]
mask = mask[:,np.argsort(g.dendrogram_col.reordered_ind)]
# run the clustermap again with the new mask
grafico_correlacao_renda_variavel_long_biased = sns.clustermap(correlacao_renda_variavel_long_biased, linewidths=.5,figsize=(40,40),annot= True,mask=mask,annot_kws={"size": 25})

我希望这不会来得太晚。我也遇到了同样的问题,找到了你的问题。你知道吗

相关问题 更多 >

    热门问题