Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress drawing dendrograms but still cluster in seaborn?

Tags:

python

seaborn

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.

like image 869
mac389 Avatar asked Sep 06 '25 03:09

mac389


1 Answers

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.

like image 115
mac389 Avatar answered Sep 07 '25 19:09

mac389