seaborn.
clustermap
(data, pivot_kws=None, method=’average’, metric=’euclidean’, z_score=None, standard_scale=None, figsize=None, cbar_kws=None, row_cluster=True, col_cluster=True, row_linkage=None, col_linkage=None, row_colors=None, col_colors=None, mask=None, **kwargs)¶Plot a matrix dataset as a hierarchically-clustered heatmap.
Parameters: |
|
---|---|
Returns: |
|
Notes
The returned object has a savefig
method that should be used if you
want to save the figure object without clipping the dendrograms.
To access the reordered row indices, use:
clustergrid.dendrogram_row.reordered_ind
Column indices, use:
clustergrid.dendrogram_col.reordered_ind
Examples
Plot a clustered heatmap:
>>> import seaborn as sns; sns.set(color_codes=True)
>>> iris = sns.load_dataset("iris")
>>> species = iris.pop("species")
>>> g = sns.clustermap(iris)
Use a different similarity metric:
>>> g = sns.clustermap(iris, metric="correlation")
Use a different clustering method:
>>> g = sns.clustermap(iris, method="single")
Use a different colormap and ignore outliers in colormap limits:
>>> g = sns.clustermap(iris, cmap="mako", robust=True)
Change the size of the figure:
>>> g = sns.clustermap(iris, figsize=(6, 7))
Plot one of the axes in its original organization:
>>> g = sns.clustermap(iris, col_cluster=False)
Add colored labels:
>>> lut = dict(zip(species.unique(), "rbg"))
>>> row_colors = species.map(lut)
>>> g = sns.clustermap(iris, row_colors=row_colors)
Standardize the data within the columns:
>>> g = sns.clustermap(iris, standard_scale=1)
Normalize the data within the rows:
>>> g = sns.clustermap(iris, z_score=0)