Python igrap创建手动图

时间:2014-07-27 17:03:11

标签: python

我是Python / igraph的新手,想要手动绘制网络。


from igraph import *

g = Graph(directed = True)

#now create simple directed graph

Tomas -> Dennis, Dennis -> Hans, Hans -> Tomas, Dennis -> Bert

g.vs["name"] = ["Tomas", "Dennis", "Hans", "Tomas", "Bert"]

layout = g.layout_kamada_kawai()

g.vs["label"] = g.vs["name"]

layout = g.layout("kamada_kawai")

plot(g, layout=layout)

是否可以在连接上做标签。(无向/定向车道)

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

from igraph import *

g = Graph(directed = True)
g.add_vertices(5)
g.add_edges([(0,1),(1,2),(2,3),(1,4)])

g.vs["name"] = ["Tomas", "Dennis", "Hans", "Tomas_2", "Bert"]
g.vs["label"] = g.vs["name"]

#Next I count the number of edges and I give numbers as names

g.es["name"] = range(g.ecount())
g.es["label"] = g.es["name"]

plot(g)

您应该得到以下内容:

Fig