Draw dendrogram in python manually

Viewed 5788

I have implemented an algorithm to solve the problem of clustering in a graph. I used the python library "python-graph" to represent the graph. Now, at each step of my computation (the algorithm is iterative) I have to draw a part of the dendrogram. In fact, the algorithm is divisive, in the sense that starting from the original graph calculates the clusters. Now, I don't know what to use to draw the dendrogram (someone suggested PIL, but I'm looking for something easy and I don't know how to use PIL)... can you suggest something and show me how to do plot with it?

Note: I read other questions but everything seems to use methods that use automatic computation of the clusters... this is not what I'm looking for: I need to manually draw the dendrogram or at least find a way to represent the clusters computed to be drawn.

Thanks!

4 Answers

You can use the plotting function inside scipy dendrogram. For this you would need to generate the same data as output by scipy dendrogram. Example:

from scipy.cluster.hierarchy import dendrogram,  _plot_dendrogram
# Generate data for plot without plotting:
ddata = dendrogram(linked_data, no_plot=True)  

MaxVerticalAxis = 120  # You can choose max value or take it from ddata["ddcoord"]

#Plotting command:
_plot_dendrogram(ddata["icoord"], ddata["dcoord"], ddata["ivl"], 30,20, MaxVerticalAxis,  "top", False, ddata["color_list"], leaf_font_size=None, leaf_rotation=None, contraction_marks=None, ax=None, above_threshold_color='C0')
Related