专门在 seaborn 集群图中更改热图的大小?

Changing the size of the heatmap specifically in a seaborn clustermap?

我正在 seaborn 中制作聚类热图,如下所示

import numpy as np
import seaborn as sns
np.random.seed(2)
data = np.random.randn(100, 10)
sns.clustermap(data)

但是行被压扁了:

但如果我将大小传递给 clustermap 函数,那么它看起来很糟糕

有没有办法只增加热图部分的大小?这样可以读取行名称,但不会拉伸集群部分。

正如@mwaskom 评论的那样,我能够将 ax_heatmap.set_positionget_position 函数一起使用以获得正确的结果。

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

np.random.seed(2)
data = np.random.randn(100, 10)
cm = sns.clustermap(data)
hm = cm.ax_heatmap.get_position()
plt.setp(cm.ax_heatmap.yaxis.get_majorticklabels(), fontsize=6)
cm.ax_heatmap.set_position([hm.x0, hm.y0, hm.width*0.25, hm.height])
col = cm.ax_col_dendrogram.get_position()
cm.ax_col_dendrogram.set_position([col.x0, col.y0, col.width*0.25, col.height*0.5])

这可以通过在 kw 参数中传递树状图比率的值来完成

import numpy as np
import seaborn as sns
np.random.seed(2)
data = np.random.randn(100, 10)
sns.clustermap(data,figsize=(12,30),dendrogram_ratio=0.02,cmap='RdBu')