[scikit-learn] Using text labels in dendrogram

Mahmood Naderan mahmood.nt at gmail.com
Mon Dec 14 11:31:24 EST 2020


Hi
I use the following code to create a dendrogram from a set of x-y points

import matplotlib.pyplot as plt
import numpy as np
from scipy.cluster.hierarchy import dendrogram, linkage
a = np.array([
[5.840,-2.339],
[6.320,-2.665],
[-1.698,-0.084],
],)
linked = linkage(a, 'single')
labelList = range(1, 69)
dendrogram(linked,
            orientation='top',
            labels=labelList,
            distance_sort='descending',
            show_leaf_counts=True)
plt.show()

This code automatically assigns labels for the points and the result is not
sorted. For example, the x-axis labels are 2 1 3.
I want to assign a text for each point. Then no matter where the point
goes, I can see the text that I have assigned. For example, I want to see
PDD, XDD, BDD.
How can I create a list of text labels and bind that to the array a?

Regards,
Mahmood
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scikit-learn/attachments/20201214/1cfd74db/attachment.html>


More information about the scikit-learn mailing list