绘制大量的networkx图:数组太大 [英] Drawing massive networkx graph: Array too big

查看:893
本文介绍了绘制大量的networkx图:数组太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制带有加权边的networkx图,但是现在我遇到了一些困难.

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:

节点数:103362 边数:1419671

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:数组太大.

ValueError: array is too big.

它是由spring_layout算法触发的.知道是什么原因造成的吗?即使当我使用其他pos算法时,我也会遇到相同的错误,如何避免(如果可以的话)?

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?

感谢您的耐心等候.

根据我的评论进行

我正在尝试调查我拥有的数据的密度.基本上,我正在看50,000场比赛,每场比赛有10位玩家,每当有两位玩家在游戏中相遇时,我+1他们之间优势的权重.我的想法是,我的最终结果将向我展示我的数据集的实力.在我的脑海中,我想要最重的边缘在中心,并且当我们从中心移出时,数据的连接密度会降低.

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.

推荐答案

问题出在spring_layout方法上.拥有如此多的节点,将需要一些时间来计算所有节点之间的相对位置.对于这么多的节点,我建议您自己弄清楚x,y的位置,或者绘制更小的子图. (< 5000个节点,或者您的计算机在一段时间内可能会变慢.

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.

这是erdos_renyi_graph(随机选择的边)中的1000个节点的样子.

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

它拉开了2个节点以突出显示.

It pulled off 2 nodes to highlight.

接下来是1500的样子 它有更多细节.现在有7-8个有趣的节点.

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.

要获得每个节点的x,y位置,请看一下.在NetworkX中的显示带有节点的图在精确的(x,y)位置.结果旋转

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

这篇关于绘制大量的networkx图:数组太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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