0

我有一个非常复杂的图表,其中包含许多节点和边。为了更好地理解,我想可视化图表。我与很多图书馆合作,但没有得到我想要的。

这篇文章很棒,但我无法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()

最佳试验: 试验图输出

4

0 回答 0