Labels for clustermap in seaborn? Labels for clustermap in seaborn? python python

Labels for clustermap in seaborn?


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.

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)

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 columnscg.dendrogram_row.linkage # linkage matrix for rows


import seaborn as sns   g = sns.clustermap(heatmap_df, metric="correlation") plt.setp(g.ax_heatmap.get_yticklabels(), rotation=0)  # For y axisplt.setp(g.ax_heatmap.get_xticklabels(), rotation=90) # For x axis


A bit different way to rotate labels

g.ax_heatmap.set_yticklabels(g.ax_heatmap.get_yticklabels(), rotation=0)