多くのノードとエッジを含む非常に複雑なグラフがあります。理解を深めるために、グラフを視覚化したいと思います。多くのライブラリを使用しましたが、必要なものが得られませんでした。
この記事pos
は素晴らしかったのですが、グラフの属性を定義できませんでした。ランダム ジオメトリック グラフには、pos
デフォルトで属性があります。
number of nodes = 567
number of edges = 846
nx.random_layout() を使用して、ノードの「pos」属性を定義しました。私のグラフ名は taradodGraph です
pos = nx.random_layout(taradodGraph)
dmin = 1
ncenter = 0
for n in pos:
x, y = pos[n]
d = (x - 0.5)**2 + (y - 0.5)**2
if d < dmin:
ncenter = n
dmin = d
# color by path length from node near center
p = dict(nx.single_source_shortest_path_length(taradodGraph, ncenter))
plt.figure(figsize=(8, 8))
nx.draw_networkx_edges(taradodGraph, pos, nodelist=[ncenter], alpha=0.4)
nx.draw_networkx_nodes(taradodGraph, pos, nodelist=list(p.keys()),
node_size=80,
node_color=list(p.values()),
cmap=plt.cm.Reds_r)
plt.xlim(-0.05, 1.05)
plt.ylim(-0.05, 1.05)
plt.axis('off')
plt.savefig('foo.png')
plt.show()