29

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

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

How do I still 2D cluster but suppress the dendrograms?

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.

3 Answers 3

36

The answer is buried in the documentation.

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])

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

3
  • What are you expecting set_axis_off to do?
    – mwaskom
    Commented Feb 24, 2017 at 16:50
  • Make the axes invisible. The frame would still, of course, be visible.
    – mac389
    Commented Feb 24, 2017 at 23:09
  • I had to add cm.ax_cbar.set_visible(False) as well to hide the cbar tick labels! Commented Dec 29, 2021 at 11:29
1

To build on the answer by mac389, if you want to suppress the dendrogram in both columns and rows do the following:

cg.ax_row_dendrogram.set_visible(False) #suppress row dendrogram

cg.ax_col_dendrogram.set_visible(False) #suppress column dendrogram

You can also suppress the cbar as indicated by Yacine.

0

Actually the easiest way to do that would be by using the tree_kwd argument to set the linewidts parameter of the underlying matplotlib.collections.LineCollection object to zero.

clustermap(YOUR_DATA, tree_kws={"linewidths": 0.})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.