簡體   English   中英

如何使用圖形工具可視化時態網絡?

[英]How can I visualize temporal network using graph-tool?

我在grap-tool(Python 3.4)中有20個有向圖,並且所有圖都有相同的節點名稱(它是一個屬性,稱為“名稱”),但是在連接和屬性方面有所不同。

我正在嘗試繪制隨時間變化的網絡(即,邊緣在每個時間步長如何變化以及顏色等屬性如何變化)。 為此,我需要為所有圖固定節點的位置。

我嘗試了這個:

import graph_tool.all as gt

## networks = {dictionary of time as the key and the Graph as the value}

#getting the positions of the nodes once that should be fixed across Graphs
initial_pos = gt.arf_layout(networks[0],weight=None, d=0.5,
                    a=10, dt=0.001, epsilon=1e-06, max_iter=100, pos=None, dim=2)

for round_id in range(0,20):
    G = networks[round_id]
    fixed_pos = gt.arf_layout(G, max_iter=0, pos=initial_pos)
    deg = G.degree_property_map("in")
    deg.a = 15 * deg.a + 25
    gt.graph_draw(
        G,
        #pos=fixed_pos,
        vertex_fill_color=G.vertex_properties["color"],
        vertex_font_size=18,
        vertex_size = deg,
        vertex_shape = G.vertex_properties["shape"],
        edge_pen_width = 5,
        output_size=(1000, 1000), 
        output=("{0}.pdf".format(round_id))
    )

但這給了我以下錯誤:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-68-4efd39b32b83> in <module>()
      5     #f, ax = plt.subplots(nrows=1, ncols=1, figsize=(17, 10), sharex=True)
      6     G = nx2gt(networks[round_id])
----> 7     fixed_pos = gt.arf_layout(G, max_iter=0, pos=initial_pos)
      8     deg = G.degree_property_map("in")
      9     deg.a = 15 * deg.a + 25

/Users/amaatouq/anaconda/lib/python3.4/site-packages/graph_tool/draw/__init__.py in arf_layout(g, weight, d, a, dt, epsilon, max_iter, pos, dim)
    393 
    394     ug = GraphView(g, directed=False)
--> 395     libgraph_tool_layout.arf_layout(ug._Graph__graph, _prop("v", g, pos),
    396                                     _prop("e", g, weight), d, a, dt, max_iter,
    397                                     epsilon, dim)

/Users/amaatouq/anaconda/lib/python3.4/site-packages/graph_tool/__init__.py in _prop(t, g, prop)
    177         raise ValueError("Expected '%s' property map, got '%s'" %
    178                          (names[t], names[prop.key_type()]))
--> 179     return pmap._get_any()
    180 
    181 

/Users/amaatouq/anaconda/lib/python3.4/site-packages/graph_tool/__init__.py in _get_any(self)
    389         g = self.get_graph()
    390         if t == "v":
--> 391             N = g.num_vertices(True)
    392         elif t == "e":
    393             N = g.edge_index_range

AttributeError: 'NoneType' object has no attribute 'num_vertices'

似乎是arf_layout()中的錯誤。 您可以通過以下方法解決此問題:

initial_pos = networks[0].own_property(initial_pos)

在進一步使用之前。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM