绘制一个树形图,根节点在顶部 [英] Plot a tree-like graph with root node at the top

查看:120
本文介绍了绘制一个树形图,根节点在顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但是,似乎没有布局将根顶点(id 0,标签A)放到顶部并向下增长.

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

我想念什么吗?

推荐答案

好的,我将其添加为评论的答案.

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

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

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)

这篇关于绘制一个树形图,根节点在顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆