可以使用哪些Networkx图表?

时间:2015-03-02 10:16:52

标签: python-2.7 matplotlib graph networkx

我有混合自然数据。数据将节点,边和社区混合在一起,我想将它们绘制成图形并将其可视化以理解模式。我正在寻找像附图一样的东西。 enter image description here此程度未知。我确实检查了networkx文档,但找不到任何接近我正在寻找的内容。这是一个非定向和非定向图。我可以将数据分开并将它们绘制成不同的格式,但是当涉及到实时分离是不可能的。数据就像一个流,这些独立的节点可以或者也可能在未来的数据出现中形成社区,因此无法将它们分开。

数据模式如下所示

2344
2424 3535
2445
2434 5525 3454 4335 2355
2342 3453 5555 2425 5255
3423 2525
2344
5234 3455 4555

节点,边和社区以时间间隔显示重复行为

1 个答案:

答案 0 :(得分:2)

您可以使用NetworkX的标准无向图类中的方法/函数add_nodes_from()add_edges_from()找到herehere。这样,您可以在数据流到来时逐步创建图形。 您所要做的就是将数据转换为正确的格式并将其传递给#34;逐行"进入这两个功能。它们只会在图形中添加节点或边缘(如果它们尚未存在)。 add_edges_from()还添加了添加边的新节点,但这显然不适用于只有一个节点的数据行,因为一个节点不会形成边。 我建议做这样的事情:

import networkx as nx

# create empty graph
G = nx.Graph()

# read data
data = ...

# assuming you can acces the lines of your data through an iterator, add them to the graph
for line in data:
    G.add_nodes_from(line)
    # get the number of nodes in the data line
    number_of_nodes = get_number_of_nodes(line)
    if number_of_nodes > 1:
        # get edgelist from data line and add it to the graph
        edgelist = get_edgelist(line)
        G.add_edges_from(edgelist)

当然还有一些工作需要转换功能" get_number_of_nodes()get_edgelist(),但这只是一个开始......

相关问题