kamicollo / idendrogram

Interactive dendrograms using Altair, Plotly and Streamlit
https://kamicollo.github.io/idendrogram/
MIT License
4 stars 0 forks source link

truncate_mode = None #13

Open wangjiawen2013 opened 10 months ago

wangjiawen2013 commented 10 months ago

Hi, truncate_mode=None will cause error when creating_dendrogram using idd.create_dendrogram(truncate_mode=None)

kamicollo commented 10 months ago

Could you share an example and the error it produces? I cannot reproduce it, e.g - using the dataset from the other issue you posted works without issues:

x, y = np.meshgrid(range(-5, 5), range(-5, 5))
z = x ** 2 + y ** 2
#Convert this grid to columnar data expected by Altair

source = pd.DataFrame({'x': x.ravel(),
'y': y.ravel(),
'z': z.ravel()})

df = source.pivot(columns='y',index='x',values='z')
column_linkage_matrix = sch.linkage(df.drop_duplicates(), method='single', metric='euclidean')
column_flat_clusters = sch.fcluster(column_linkage_matrix, t=0, criterion='distance')
column_cl_data = idendrogram.ClusteringData(
linkage_matrix = column_linkage_matrix,
cluster_assignments = column_flat_clusters
)
column_idd = idendrogram.idendrogram()
column_idd.set_cluster_info(column_cl_data)

column_dendrogram = column_idd.create_dendrogram(truncate_mode=None).plot(
backend='altair',
orientation='top',
height=30, width=200,
show_nodes=False).interactive()
column_dendrogram
wangjiawen2013 commented 9 months ago

I know why. I thought it was caused by truncate_mode=None, but it's the same error caused by duplicates. When the duplicated data was removed, truncate=None worked well.