Add optional hierarchical clustering for heatmap rows and columns, including coordinated row and column dendrograms.
- SciPy can handle the clustering calculation, but this introduces a SciPy dependency.
- All distance metrics and linkage methods that are exposed in SciPy can be included as options for the parameters distance and method parameters. Default distance = euclidian, method = complete.
- Parameter "clustering" with options: features, samples, both, none
High-level workflow:
input matrix
→ optionally standardize values
→ calculate row and column pairwise distances with scipy.spatial.distance.pdist
→ compute hierarchical linkage with scipy.cluster.hierarchy.linkage
→ obtain dendrogram geometry and leaf order with scipy.cluster.hierarchy.dendrogram(no_plot=True)
→ reorder heatmap rows and columns by leaf order
→ convert SciPy dendrogram coordinates into line-segment data
→ render the heatmap and dendrogram line segments in Vega
The Vega specification can use generic rule marks to render every dendrogram branch from the generated segment data; branches do not need to be manually hard-coded.
Codex code Example:
scipy-vega-clustered-heatmap.py
Plot:

Add optional hierarchical clustering for heatmap rows and columns, including coordinated row and column dendrograms.
High-level workflow:
The Vega specification can use generic rule marks to render every dendrogram branch from the generated segment data; branches do not need to be manually hard-coded.
Codex code Example:
scipy-vega-clustered-heatmap.py
Plot: