Drawing massive networkx graph: Array too big

最后都变了- 提交于 2019-12-13 18:23:30

问题


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.


回答1:


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.

It pulled off 2 nodes to highlight.

Next is what 1500 looks like

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



来源:https://stackoverflow.com/questions/22908247/drawing-massive-networkx-graph-array-too-big

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!