Seaborn中的clustermap的标签? [英] Labels for clustermap in seaborn?
问题描述
关于在seaborn
中为clustermap
进行标签的问题,我有几个问题.首先,可以提取用于层次聚类的距离值,并在树形结构可视化(可能只有前三个级别)上绘制该值.
I have several questions about labeling for clustermap
in seaborn
. First is it possible to extract the the distance values for the hierarchical clustering, and plot the value on the tree structure visualization (maybe only the first three levels).
这是我创建簇图图的示例代码:
Here is my example code for creating a clustermap plot:
import pandas as pd
import numpy as np
import seaborn as sns
get_ipython().magic(u'matplotlib inline')
m = np.random.rand(50, 50)
df = pd.DataFrame(m, columns=range(4123, 4173), index=range(4123, 4173))
sns.clustermap(df, metric="correlation")
其他两个问题是:
-由于y标签重叠在一起,因此如何旋转.
-如何将颜色栏移至底部或右侧. (对于热图,有一个问题,但确实有不适合我的情况,也不能解决颜色
栏位置)
The other two questions are:
- How to rotate the y labels since they overlaps together.
- How to move the color bar to the bottom or right. (There was a question for heatmap, but does not work for my case. Also does not address the color
bar position)
推荐答案
我在旋转y轴上的标签时遇到了完全相同的问题,并找到了解决方案.
问题是,如果您按照引用的问题中的建议进行plt.yticks(rotation=0)
操作,由于ClusterGrid
的工作方式,它会旋转结肠上的标签.
I had the exact same issue with the labels on the y-axis being rotated and found a solution.
The issue is that if you do plt.yticks(rotation=0)
like suggested in the question you referenced, it will rotate the labels on your colobar due to the way ClusterGrid
works.
要解决该问题并旋转正确的标签,您需要引用基础Heatmap
中的Axes
并对其进行旋转:
To solve it and rotate the right labels, you need to reference the Axes
from the underlying Heatmap
and rotate these:
cg = sns.clustermap(df, metric="correlation")
plt.setp(cg.ax_heatmap.yaxis.get_majorticklabels(), rotation=0)
关于色条放置的其他问题,如此指示,目前我不支持此功能不幸的是,Github问题.
For your other question about the colorbar placement, I don't think this is supported at the moment, as indicated by this Github issue unfortunately.
最后,对于分层聚类距离值,您可以使用以下命令访问行或列的链接矩阵:
And finally for the hierarchical clustering distance values, you can access the linkage matrics for rows or columns with:
cg = sns.clustermap(df, metric="correlation")
cg.dendrogram_col.linkage # linkage matrix for columns
cg.dendrogram_row.linkage # linkage matrix for rows
这篇关于Seaborn中的clustermap的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!