[英]Bipartite graph in NetworkX for LARGE amount of nodes
I am trying to create bipartite of certain nodes, for small numbers it looks perfectly fine:我正在尝试创建某些节点的二分,对于少量它看起来非常好:
Image for around 30 nodes大约 30 个节点的图像
Unfortunately, this isn't the case for more nodes like this one:不幸的是,对于像这样的更多节点,情况并非如此:
My code for determining the position of each node looks something like this:我用于确定每个节点的 position 的代码如下所示:
pos = {}
pos[SOURCE_STRING] = (0, width/2)
row = 0
for arr in left_side.keys():
pos[str(arr).replace(" ","")]=(NODE_SIZE, row)
row += NODE_SIZE
row = 0
for arr in right_side.keys():
pos[str(arr).replace(" ","")]=(2*NODE_SIZE,row)
row += NODE_SIZE
pos[SINK_STRING] = (3*NODE_SIZE, width/2)
return pos
And then I feed it to the DiGraph
class:然后我将它提供给
DiGraph
class:
G = nx.DiGraph()
G.add_nodes_from(nodes)
G.add_edges_from(edges, len=1)
nx.draw(G, pos=pos ,node_shape = "s", with_labels = True,node_size=NODE_SIZE)
This doesn't make much sense since they should be in the same distance from each other since NODE_SIZE
is constant it doesn't change for the rest of the program.这没有多大意义,因为它们应该彼此保持相同的距离,因为
NODE_SIZE
是恒定的,对于程序的 rest 不会改变。
Following this thread:按照这个线程:
Didn't help me either.也没有帮到我。
Can something be done about this?可以对此做些什么吗?
Edit(Following Paul Brodersen Advice using netGraph:编辑(按照 Paul Brodersen 建议使用 netGraph:
Used this documentation: netgraph doc使用此文档: netgraph doc
And still got somewhat same results, such as: netgraph try并且仍然得到了一些相同的结果,例如: netgraph try
Using edges and different positions, also played with node size, with no success.使用边缘和不同的位置,也使用节点大小,但没有成功。
Code:代码:
netgraph.Graph(edges, node_layout='bipartite', node_labels=True)
plt.show()
In your netgraph call, you are not changing the node size.在您的 netgraph 调用中,您不会更改节点大小。 My suggestion with 30 nodes:
我对 30 个节点的建议:
import numpy as np
import matplotlib.pyplot as plt
from netgraph import Graph
edges = np.vstack([np.random.randint(0, 15, 60),
np.random.randint(16, 30, 60)]).T
Graph(edges, node_layout='bipartite', node_size=0.5, node_labels=True, node_label_offset=0.1, edge_width=0.1)
plt.show()
With 100 nodes:有 100 个节点:
import numpy as np
import matplotlib.pyplot as plt
from netgraph import Graph
edges = np.vstack([np.random.randint(0, 50, 200),
np.random.randint(51, 100, 200)]).T
Graph(edges, node_layout='bipartite', node_size=0.5, node_labels=True, node_label_offset=0.1, edge_width=0.1)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.