2
votes

I have 1000 different names, each constituting a node. Each name can be connected with 0..1000 other names an unlimited amount of times. I would like to graph it in such a way that the distance between two nodes is inversely proportional to the number of times they are connected.

Example:

'node1' : ['node2','node2','node2','node2','node2','node3']
'node2' : ['node1','node1','node1','node1','node1']
'node3' : ['node1']

node1and node2 should huddle together and node3 should be further away.

Is that possible? Currently I'm graphing using the following code:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_nodes_from(grapharr.keys())
for k in grapharr:
    for j in grapharr[k]:
        G.add_edge(k,j)

nx.draw_networkx(G, **options)

grapharris a dict structure where the keys are nodes and the values are arrays containing the connections for the particular node.

1
I don't think that is possible for all nodes. Think about the constraints such an optimization problem would have - yatu
Is the network directed or undirected? I.e. is it always like in your example that the number of associations from A to B is the same as from B to A? If so, you could convert these to edge weights and use a force-directed / spring layout. It won't be exact due to the possible clash of constraints as @yatu mentioned, but it will be a step in the right direction. - Paul Brodersen

1 Answers

1
votes

It is impossible in the general case. Look at this graph:

enter image description here

Imagine that the central node has a thousand connections to each other, but 'square' nodes have only one connection between them. How will you draw them?

Anyway, you can set the connectivity level as edge weight and use force-directed layouts that will try to create the best layout (but not 100% optimal, of course). In networkx, there are: