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

tln*_*agy 7 python matplotlib seaborn

我在seaborn中制作了一个聚类热图,如下所示

import numpy as np
import seaborn as sns
np.random.seed(2)
data = np.random.randn(100, 10)
sns.clustermap(data)
Run Code Online (Sandbox Code Playgroud)

但行被压扁:

在此输入图像描述

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

在此输入图像描述

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

tln*_*agy 9

正如@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])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述