2016-08-12 5 views
1

私はいくつかのノード、関係を表すノード間の方向矢印、接続の強さに対する相対的な厚さを示すグラフが必要です。私はどのように力指向のグラフを作るのですか?

はRでは、これは非常に単純です

生成
library("qgraph") 
test_edges <- data.frame(
    from = c('a', 'a', 'a', 'b', 'b'), 
    to = c('a', 'b', 'c', 'a', 'c'), 
    thickness = c(1,5,2,2,1)) 
qgraph(test_edges, esize=10, gray=TRUE) 

force directed graph via R

をしかし、Pythonで、私は明確な例を見つけることができませんでした。 NetworkXとigraphはそれが可能であることを示唆しているようですが、私はそれを理解することができませんでした。

答えて

2

私は、Matrootlibを使用するNetworkXの標準描画関数でこれを最初に試みましたが、あまり成功しませんでした。

ただし、NetworkXのsupports drawing to the dot formatは、supports edge weight, as the penwidth attributeです。どの番組

dot -Tpng /tmp/graph.dot > /tmp/graph.png 
xdg-open /tmp/graph.png 

(またはあなたのOSに相当)

:ターミナルで実行グラフを表示するには、次に

import networkx as nx 

G = nx.DiGraph() 
edges = [ 
    ('a', 'a', 1), 
    ('a', 'b', 5), 
    ('a', 'c', 2), 
    ('b', 'a', 2), 
    ('b', 'c', 1), 
    ] 
for (u, v, w) in edges: 
    G.add_edge(u, v, penwidth=w) 

nx.nx_pydot.write_dot(G, '/tmp/graph.dot') 

:だからここ

は溶液で:

output of the graph described by OP

関連する問題