如何从Networkx或DyNetx的图列表中生成动态图

3

我手头有一堆边文件,我已经将它们整理成了一个图列表,但问题是我想将它们作为一个单一的动态网络来处理,但我不知道如何操作。我尝试查看networkx和dynetx的文档,但没有找到答案。

目前我所做的工作如下:

import networkx as nx
import matplotlib.pyplot as plt
from operator import itemgetter
import dynetx as dnx
#from glob import glob
import os

#path to the files
path = '../Ants'
#Create a list of graph from the files
G = [nx.read_weighted_edgelist(path+'/'+f, create_using=nx.Graph(), nodetype=int) for f in os.listdir(path) ]

1个回答

3

DyNetx软件包在其DynGraph文档中说明了一些方法。以下内容将有助于解决您的问题:

import networkx as nx
import matplotlib.pyplot as plt
from operator import itemgetter
import dynetx as dnx
#from glob import glob
import os

#path to the files
path = '../Ants'
#Create a list of graph from the files
list_of_snapshots = [nx.read_weighted_edgelist(path+'/'+f, create_using=nx.Graph(), nodetype=int) for f in os.listdir(path) ]

dynamic_graph = dnx.DynGraph()
for t, graph in enumerate(list_of_snapshots):
    dynamic_graph.add_interactions_from(graph.edges(data=True), t=t)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接