3

I'm trying to draw a networkx graph with weighted edges, but right now I'm having some difficulty.

As the title suggests, this graph is really huge:

Number of Nodes: 103362 Number of Edges: 1419671

And when I try to draw this graph with the following code:

pos = nx.spring_layout(G)
nx.draw(G, node_color='#A0CBE2',edge_color='#BB0000',width=2,edge_cmap=plt.cm.Blues,with_labels=False)
plt.savefig("edge_colormap.png") # save as png
plt.show() # display

(This is just me testing functionality, not my desired end result). I get the error:

ValueError: array is too big.

It's triggered from the spring_layout algorithm. Any idea what's causing this? Even when I use a different pos algorithm I get the same error, how can I avoid it (if I can)?

On another note, I want to colour the edges based on their weight. As you can see there are a lot of edges and probably a wide range of weights, what is the best way to do this?

Thanks for your patience.

EDIT FROM MY COMMENT:

I'm trying to investigate the density of the data I have. Basically I am looking at 50,000 matches each containing 10 players, and whenever two players meet in a game I +1 to the weight of the edge between them. The idea is that my end result will show me the strength of my data set. In my mind I want the heaviest edges at the centre and as we move out from the centre the data is less densely connected.

Community
  • 1
  • 1
user124784
  • 896
  • 1
  • 13
  • 22
  • 2
    Out of curiosity, what do you expect to see when you plot a graph with 100k nodes? I imagine it is going to be a large blob of black on your screen. – mbatchkarov Apr 07 '14 at 09:23
  • 1
    the plot will be of no practical use, why bother to display it? – EdChum Apr 07 '14 at 09:31
  • I'm trying to investigate the density of the data I have. Basically I am looking at 50,000 matches each containing 10 players, and whenever two players meet in a game I +1 to the weight of the edge between them. The idea is that my end result will show me the strength of my data set. EDIT: In my mind I want the heaviest edges at the centre and as we move out from the centre the data is less densely connected. – user124784 Apr 07 '14 at 10:20
  • In that case why not bin the nodes together to reduce the number of nodes so that it can be drawn? – EdChum Apr 07 '14 at 10:50
  • Sorry, could you be a little more specific? I'm fairly new to programming and this is my first time using this module. I'm not really sure what you mean by bin the nodes together. – user124784 Apr 07 '14 at 10:54
  • I mean group ranges of nodes together e.g. 1-5, 6-10, etc.. doesn't need to be numeric but the principal is you have 1 node represent 500 or 1000 nodes so you reduce the number of nodes without losing the shape – EdChum Apr 07 '14 at 17:18
  • Is there any easy way to do this once the graph has been constructed? Or should I implement this into building the graph? It doesn't quite achieve what I want, I'm not so interested in the shape, as that is more or less every node connected to every other node. I just want to see how the weights of those edges is distributed. i.e. is it the same 50,000 players who meet over and over, or is it pretty evenly distributed between all my nodes. – user124784 Apr 07 '14 at 19:33

1 Answers1

3

The problem lies in the spring_layout approach. With this many nodes it will take a while to calculate where all of them should go with respect to one another. With this many nodes I would suggest either figuring out the x,y positions yourself or plot much smaller subgraphs. (<5000 nodes or your computer might be a bit sluggish for a while.

Here is what 1000 nodes from an erdos_renyi_graph (randomly chosen edges) looks like. enter image description here

It pulled off 2 nodes to highlight.

Next is what 1500 looks like enter image description here It got a little more detail. Now with 7-8 interesting nodes.

There isn't much to be gained by so many edges and so many nodes on a graph. And what happens if you don't like the output, you would need to re-run it again.

To get x,y positions of each node take a look at this. in NetworkX show graph with nodes at exact (x,y) position. Result is rotated

Community
  • 1
  • 1
Back2Basics
  • 7,406
  • 2
  • 32
  • 45
  • Thanks for the effort you put into this response and I'm sorry that I didn't respond sooner. How would I go about defining my own positions for the nodes? I was thinking I could define a radial distance from a centre node using things like cores and weighted matchings. That sounds pretty complicated though.. I've decided given my data size I just want my plot to give me a rough indication of weight-density. So a sort of web in which the highest weighted edges are in the centre. Any other ideas on how I could produce this? – user124784 Apr 07 '14 at 13:20
  • I would think of a different approach to the problem. Consider grouping nodes. You can sum up the weights of the edges with other groups. Start with an easy version first, splitting up the nodes amongst 2 groups. – Back2Basics Apr 08 '14 at 03:05