can tell me how nodes' position , length of edge without calculating myself?
import networkx nx g = nx.graph() g.add_edge('a','b')
nodes don't have position unless assign 1 them. fortunately networkx has layout algorithm already implemented:
# position nodes on circle. pos = circular_layout(g[, dim, scale]) # position nodes uniformly @ random in unit square. pos = random_layout(g[, dim]) # position nodes in concentric circles. pos = shell_layout(g[, nlist, dim, scale]) # position nodes using fruchterman-reingold force-directed algorithm. pos = spring_layout(g[, dim, k, pos, fixed, ...]) # position nodes using eigenvectors of graph laplacian. pos = spectral_layout(g[, dim, weight, scale]) the return value pos dictionary of positions indexed node.
there no function give length of edges builtin once have coordinates of each node can compute length of edge using simple formula:
import math dist_node12 = math.sqrt((pos[node1][0] - pos[node2][0])**2 + (pos[node1][1] - pos[node2][1])**2)
Comments
Post a Comment