Adding hatches for certain rows and columns in clustermap

61 Views Asked by At

I have used seaborn.clustermap() to plot clustermap as shown below

labels = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v"]
sns.clustermap(data, cmap=sns.cm.rocket_r, xticklabels=labels, yticklabels=labels)

enter image description here

It is pretty clear there are two clusters, "m", "o", "d", "n", "p" vs the rest. Now I want to add hatches ("//") to the rows and columns of "m", "o", "d", "n", "p" to highlight the difference, how can I do that? Thanks.

1

There are 1 best solutions below

0
crx91 On

I found out how to do that by following the answer in this question: adding hatches to seaborn heatmap plot

mask = np.ones_like(data)
mask[idx_to_mask, :] = False
mask[:, idx_to_mask] = False
data_masked = np.ma.masked_where(mask, data)

g = sns.clustermap(data, cmap=sns.cm.rocket_r, xticklabels=labels, yticklabels=labels)
ax = g.ax_heatmap
y = x = np.arange(len(data)+1)
ax.pcolor(x, y, data_masked, hatch='//', alpha=0.)