简体   繁体   English

python igraph 边作为节点图

[英]python igraph edges as nodes graph

I have a graph in igraph :我在 igraph 中有一个图表:

import igraph as ig
vertices = [i for i in range(7)]
edges = [(0,2),(0,1),(0,3),(1,0),(1,2),(1,3),(2,0),(2,1),(2,3),(3,0),(3,1),(3,2),(2,4),(4,5),(4,6),(5,4),(5,6),(6,4),(6,5)]
g = ig.Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)

But I'm wondering if there is something already implemented in Igraph in order to get the graph with edges as nodes of the actual g graph as shown in the picture below.但我想知道 Igraph 中是否已经实现了一些东西,以便将边作为实际 g 图的节点的图,如下图所示。

在此处输入图片说明

If I am not mistaken this transformation is called a line graph, Igraph python have function call linegraph().如果我没记错的话,这个转换叫做折线图,Igraph python 有函数调用 linegraph()。

I believe this is what you are looking for.我相信这就是你正在寻找的。

Like Romain said, you can do the trick with linegraph() .就像罗曼说的,你可以用linegraph()

import igraph as ig

vertices = [i for i in range(7)]
edges = [(0,2),(0,1),(0,3),(1,0),(1,2),(1,3),(2,0),(2,1),(2,3),(3,0),(3,1),(3,2),(2,4),(4,5),(4,6),(5,4),(5,6),(6,4),(6,5)]
g = ig.Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)

# Graph g with edges as nodes
g = g.linegraph()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM