networkx/igraph(Python)上指定的边长 [英] Specified edge lengths on networkx/igraph (Python)

查看:506
本文介绍了networkx/igraph(Python)上指定的边长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我拥有的数据可视化一个网络,并想用特定的边长来绘制它们的图.我使用Python,并尝试使用networkx和igraph进行绘制,但是似乎所有对象都分配了固定的边长.

I wanted to visualize a network with the data I have and would like to graph them with specific edge lengths. I use Python, and I've tried networkx and igraph to plot but all seem to assign fixed edge lengths.

a.)我想知道我是否写错了代码,或者软件包是否真的没有能力.如何为networkx或igraph正确实现指定的边长?

a.) I wonder if I did the codes wrong or the packages aren't really capable. How do you properly implement specified edge lengths for networkx or igraph?

b.)如果networkx和igraph无法做到,那么您可能会建议哪个软件包? (最好是可以承载8万多个节点的节点.)

b.) If networkx and igraph can't do it, what package could you possibly suggest? (Preferably one that can carry over 80 thousand nodes.)

谢谢!

推荐答案

这应该有效:

import networkx as NX
import pygraphviz as PG

G = PG.AGraph()
nlist = "A B C D E".split()
a, b = "A A B", "B C D"
elist = zip(a.split(), b.split())

G.add_nodes_from(nlist)
G.add_edges_from(elist)
G.node_attr.update(color="red", style="filled")
G.edge_attr.update(color="blue", len="2.0", width="2.0")

print(G.edge_attr)
# returns {'color': 'red', 'width': '', 'len': '2.0'}

# add new edge with custom length (all others have length=2.0):
G.add_edge("C", "E", len="3.0", color="blue", width="2.0")

edge = G.get_edge("C", "E")
print(edge_attr)
# returns {'color': 'blue', 'width': '2.0', 'len': '3.0'}

# and you can confirm that introspection by drawing & printing this graph:
G.draw('somefolderandfilename.png', format='png', prog='neato')

大多数图形绘制算法都使用SMACOF的某些版本,这当然会改变边的长度.但是,graphviz布局引擎"neato"(作为上面"draw"的第二个参数提供)应尽可能保留用户设置的边长.

Most graph drawing algorithms use some version of SMACOF, which of course varies the edge length; however, the graphviz layout engine 'neato' (supplied as the 2nd argument to 'draw' above) ought to preserve, if at all possible, user-set edge lengths.

我在这里使用的库肯定足够坚固,可以处理80,000个节点.

The library i used here is certainly sturdy enough to handle 80,000 nodes.

这篇关于networkx/igraph(Python)上指定的边长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆