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: | data: 2D array-like
pivot_kws : dict, optional
method : str, optional
metric : str, optional
z_score : int or None, optional
standard_scale : int or None, optional
figsize: tuple of two ints, optional
cbar_kws : dict, optional
{row,col}_cluster : bool, optional
{row,col}_linkage : numpy.array, optional
{row,col}_colors : list-like or pandas DataFrame/Series, optional
mask : boolean array or DataFrame, optional
kwargs : other keyword arguments
|
---|---|
Returns: | clustergrid : ClusterGrid
|
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)