Plot a tree-like graph with root node at the top

自闭症网瘾萝莉.ら 提交于 2019-12-02 06:46:02

问题


I have the following toy graph that represents, for instance, a forum thread:

import igraph as ig
g = ig.Graph(n = 12, directed=True)
g.add_edges([(1,0),(2,1), (3,2), (4,3),
             (5,1),
             (6,2), (7,6), (8,7),
             (9,0),
             (10,0), (11,10)])
g.vs["label"] = ["A", "B", "A", "B", "C", "F", "C", "B", "D", "C", "D", "F"]
ig.plot(g, layout="kk")

However, there seems to be no layout that places the root vertex (id 0, label A) into the top and grows downwards.

Am I missing something?


回答1:


OK, I'll just add this as an answer, for the comments.

So the Reingold-Tilford layout works: http://igraph.sourceforge.net/doc/python/igraph.Graph-class.html#layout_reingold_tilford

layout = g.layout_reingold_tilford(mode="in", root=0)


来源:https://stackoverflow.com/questions/20213956/plot-a-tree-like-graph-with-root-node-at-the-top

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!