qis.plot_clusters

qis.plot_clusters(clusters, linkages, cutoffs, figsize=(14, 10), *, axes=None, table_ax=None, titles=None, display_names=None, fontsize=10, show_distance=False, table_title='Cluster IDs', table_kwargs=None, cluster_labels=None, portfolio_weights=None)[source]

Render supplied trees and membership with automatic or caller-owned axes.

The aggregate ordering preserves OP’s contract: concatenate in reverse linkage-key order, sort by cadence-prefixed cluster ID, then reverse that sorted Series. Display aliases do not change the asset IDs or ordering in the returned Series. Any positive number of disjoint groups/cadences is supported; no fit is performed.

Parameters:
  • clusters (Mapping[str, Series]) – Cadence/group to asset-indexed membership Series in linkage leaf order.

  • linkages (Mapping[str, ndarray]) – Matching group to full SciPy linkage array. A singleton uses shape (0, 4).

  • cutoffs (Mapping[str, float]) – Matching group to finite nonnegative merge-distance cutoff.

  • figsize (tuple[float, float]) – Figure size when axes are created automatically.

  • axes (Mapping[str, Axes] | None) – Optional group-to-axis mapping, with exactly the input groups.

  • table_ax (Axes | None) – Membership-table axis, required together with axes.

  • titles (Mapping[str, str] | None) – Optional group headings; defaults use Monthly/Quarterly for ME/QE.

  • display_names (Mapping | None) – Optional asset-ID-to-display-name mapping, used only for rendering.

  • fontsize (float) – Leaf and table font size.

  • show_distance (bool) – Display merge-distance ticks.

  • table_title (str) – Heading above the membership table.

  • table_kwargs (dict | None) – Additional qis table options, including colour and column widths.

  • cluster_labels (Mapping[str, str] | None) – Optional cadence-prefixed cluster-ID to descriptive label mapping.

  • portfolio_weights (Series | None) – Optional asset-indexed signed decimal weights. Must cover every displayed asset; no normalisation is applied. Its name supplies the column heading, defaulting to Portfolio weight. Extra asset IDs are ignored.

Returns:

Cadence-prefixed membership Series with original asset IDs, and its figure.

Raises:

ValueError – If groups, trees, asset identities, cutoffs or supplied axes disagree.

Return type:

tuple[Series, Figure]