Reputation: 103
I generated a clustermap using seaborn.clustermap
. I wanted to show the row_colors
option to highlight some clusters but this is the result I got:
clustermap with missing row_colors
Here you can find my code:
pal = sns.light_palette('red', np.unique(labels).size)
lut = dict(zip(np.unique(labels), pal))
row_colors = pd.Series(labels, name='clusters').map(lut)
sns.clustermap(my_data, method='ward', robust=True, row_colors=row_colors)
However if I run the example from the seaborn documentation I don't have any problem:
iris = sns.load_dataset("iris")
species = iris.pop("species")
lut = dict(zip(species.unique(), "rbg"))
row_colors = species.map(lut)
g = sns.clustermap(iris, row_colors=row_colors)
Why does the highlighting not work in my code?
Upvotes: 2
Views: 3345
Reputation: 103
Thank you very much for you answer error. I found out the problem. I have a MultiIndex dataframe and for some reason it doesn't plot the row_color. Actually this is the only difference with the iris example code.
And I just fixed the problem doing this:
sns.clustermap(my_data.reset_index(drop=True), method='ward', robust=True, row_colors=row_colors)
and now it works:
I don't know whether this can be considered as a bug but it looks like. Perhaps that can help to fix it.
Upvotes: 6