publiplots.dendrogram

publiplots.dendrogram(linkage=None, data=None, method='ward', metric='euclidean', orientation='top', color=None, linewidth=None, ax=None, **kwargs)[source]

Draw a dendrogram.

Parameters:
  • linkage (ndarray, optional) – Precomputed linkage matrix. If None, computed from data.

  • data (DataFrame, optional) – Data to cluster (if linkage not provided).

  • method (str, default="ward") – Clustering linkage method.

  • metric (str, default="euclidean") – Distance metric.

  • orientation (str, default="top") – Dendrogram orientation: ‘top’, ‘bottom’, ‘left’, ‘right’.

  • color (str, optional) – Line color. Uses rcParams default if None.

  • linewidth (float, optional) – Line width. Uses rcParams default if None.

  • ax (Axes, optional) – Matplotlib axes.

  • **kwargs – Additional arguments passed to scipy.dendrogram.

Returns:

The axes where the dendrogram was drawn.

Return type:

Axes

Examples

Dendrogram from raw data:

>>> ax = pp.dendrogram(data=df, method="ward", metric="euclidean")

Dendrogram from a precomputed linkage (e.g. sharing linkage with a heatmap):

>>> from scipy.cluster.hierarchy import linkage
>>> Z = linkage(df.values, method="ward")
>>> ax = pp.dendrogram(linkage=Z, orientation="left")

See also

publiplots.complex_heatmap

Automatically attaches dendrograms when row_cluster=True or col_cluster=True.

publiplots.heatmap

Standard heatmap primitive.