mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.43k stars 1.91k forks source link

How to define row/column colors without using row/column clustering in heatmap/clustermap #486

Closed fbrundu closed 9 years ago

fbrundu commented 9 years ago

Hi all, I am trying to figure out if there is a way to define row/column colors using heatmap or clustermap, such as using the {row,col}_colors parameter in clustermap but without the need for a clustering or dendrogram over row and columns. Using it with {row,col}_cluster=False produces:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-5d656f053811> in <module>()
      2 act, samples = results_anova.shape
      3 plt.figure(1, figsize=[samples/5, act/5])
----> 4 sns.clustermap(results_anova, col_colors=col_colors, figsize=(samples/5, act/5), col_cluster=False, row_cluster=False)
      5 plt.savefig("heatmap_anova.svg", bbox_inches="tight")
      6 plt.savefig("heatmap_anova.pdf", bbox_inches="tight")

/usr/local/lib/python3.4/dist-packages/seaborn/matrix.py in clustermap(data, pivot_kws, method, metric, z_score, standard_scale, figsize, cbar_kws, row_cluster, col_cluster, row_linkage, col_linkage, row_colors, col_colors, mask, **kwargs)
    893                         row_linkage=row_linkage, col_linkage=col_linkage,
    894                         mask=mask,
--> 895                         **kwargs)

/usr/local/lib/python3.4/dist-packages/seaborn/matrix.py in plot(self, metric, method, colorbar_kws, row_cluster, col_cluster, row_linkage, col_linkage, mask, **kws)
    810         self.plot_dendrograms(row_cluster, col_cluster, metric, method,
    811                               row_linkage=row_linkage, col_linkage=col_linkage)
--> 812         self.plot_colors(**kws)
    813         self.plot_matrix(colorbar_kws, mask, **kws)
    814         return self

/usr/local/lib/python3.4/dist-packages/seaborn/matrix.py in plot_colors(self, **kws)
    782         if self.col_colors is not None:
    783             matrix, cmap = self.color_list_to_matrix_and_cmap(
--> 784                 self.col_colors, self.dendrogram_col.reordered_ind, axis=1)
    785             heatmap(matrix, cmap=cmap, cbar=False, ax=self.ax_col_colors,
    786                     xticklabels=False, yticklabels=False,

AttributeError: 'NoneType' object has no attribute 'reordered_ind'

Is that possible?

Thanks

mwaskom commented 9 years ago

It should be possible; this looks like a bug.

fbrundu commented 9 years ago

I tried the current development version 0.6.dev0 and it seems to work, although I have not tested it extensively..

mwaskom commented 9 years ago

Oh right, I think this was fixed by #380 maybe?

mwaskom commented 9 years ago

Closing as I think this is fixed but let me know if you still have issues.

fbrundu commented 9 years ago

Yes, I think it is fixed now. I will let you know if I have issues. Thanks :)