✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Interactive dengoram with plotly and custom distance, linkage functions


I have a matrix X and usually I use scipy to make a dendogram and plot it:

from scipy.cluster.hierarchy import dendrogram, linkage
from scipy.spatial.distance import squareform
distances = np.sqrt((1 - X).round(5) / 2)
clusters = linkage(squareform(distances.values), method='ward')

However, in my case X is 900x900 matrix, so matplotlib can’t plot all the features on a single plot in an interpretable way. I tried to use plotly dendogram function:

fig = ff.create_dendrogram(X, linkagefun=lambda x: linkage(x, 'ward'), distfun=lambda x: np.sqrt((1 - x).round(5) / 2))

However, plots and distances are different from scipy.dendogram function output. How can I configure plotly to get the same result?


HI @oleksandrproskurin,
To understand how ff.create_dendogram () works
you can inspect the code here: