【问题标题】:Plot a tree-like graph with root node at the top绘制一个根节点在顶部的树状图
【发布时间】:2013-11-27 06:02:48
【问题描述】:

我有以下玩具图,例如,代表论坛主题:

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")

但是,似乎没有将根顶点(id 0,标签 A)置于顶部并向下增长的布局。

我错过了什么吗?

【问题讨论】:

  • 好吧,这样就完成了,抱歉我没有在文档中看到参数:layout = g.layout_reingold_tilford(mode="in", root=0)

标签: python igraph


【解决方案1】:

好的,我将添加这个作为答案,供 cmets 使用。

所以 Reingold-Tilford 布局有效:http://igraph.sourceforge.net/doc/python/igraph.Graph-class.html#layout_reingold_tilford

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-27
  • 1970-01-01
相关资源
最近更新 更多