如何抑制绘制树状图但仍然聚集在seaborn中?

问题描述:

我想在 seaborn 中绘制一个集群图,按行和列进行聚类.我不想绘制树状图.

I want to plot a clustermap in seaborn, clustered by both rows and columns. I do not want to draw the dendrograms.

设置 row_cluster=Falsecol_cluster=False 会移除树状图,但也会停止聚类.

Setting row_cluster=False or col_cluster=False removes the dendrograms, but also stops the clustering.

如何仍然使用 2D 聚类但抑制树状图?

这个问题提供了设置宽度的技巧树状图行数为 0.此 hack 在 seaborn 0.7.1 中不起作用.

This question provides a hack of setting the width of the dendrogram lines to 0. This hack does not work in seaborn 0.7.1.

答案隐藏在文档中.

cg 成为 Seaborn 返回的 clustermap 实例.

Let cg be the clustermap instance returned by Seaborn.

绘制聚类图后,键入以下内容以删除行树状图.

After drawing the clustermap, type the following to remove the row dendrogram.

cg.ax_row_dendrogram.set_visible(False)

如果要保留图例,请键入:

If you want to preserve the legend, type:

cg.ax_row_dendrogram.set_xlim([0,0])

这是一个 hack,但是 set_axis_off() 在 Seaborn 中似乎没有在 matplotlib 中做的那样.

This is a hack, but set_axis_off() does not seem to do in Seaborn what it does in matplotlib.