开发者

Draw dendrogram in python manually

开发者 https://www.devze.com 2023-03-15 06:46 出处:网络
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

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开发者_Python百科 (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!


Code to implement scipy dendrogram can be found here and this simple implementation will help you to move on.


perhaps an other solution could be this one: http://ete.cgenomics.org/ I recommend you the main help pdf to start: http://ete.cgenomics.org/releases/ete2/doc/ete_tutorial.pdf


The ETE python toolkit gives you a lot of possibilities for tree drawing. The drawing engine allows for programmatic tree rendering. Trees can be plotted as PNG or SVG images. Dendrograms can be represented as rectangular or circular tress.

Although ETE is commonly used to deal with phylogenetic trees, it provides also a clustering module, with several special predefined visualization modes.

Check some examples at http://packages.python.org/ete2/tutorial/tutorial_drawing.html


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号