use*_*574 4 thickness networkx
如何在网络x中按厚度绘制N> 1000个节点的加权网络?如果我有一个.csv列表的源,目标节点和每个边的权重,我正在考虑使用该方法:
for i in range(N)
G.add_edge(source[i],target[i], weight=weight[i])
nx.draw_networkx_edges(G)
Run Code Online (Sandbox Code Playgroud)
但是,我必须给每一条边都加厚吗?或每组边缘厚度相似?
Bon*_*fum 11
您可以单独指定每个边,或者如果您具有计算分组的某些功能(然后使用多个调用draw_network_edges),则可以在组中定义它们.
下面是一个使用边缘权重的随机图的示例,首先定义边缘厚度,然后使用数据作为着色.
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
n = 15; m = 40
# select some edge destinations
L = np.random.choice(xrange(n), 2*m)
# and suppose that each edge has a weight
weights = 0.5 + 5 * np.random.rand(m)
# create a graph object, add n nodes to it, and the edges
G = nx.DiGraph()
G.add_nodes_from(xrange(n))
for i, (fr, to) in enumerate(zip(L[1::2], L[::2])):
G.add_edge(fr, to, weight=weights[i])
# use one of the edge properties to control line thickness
edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]
# layout
pos = nx.spring_layout(G, iterations=50)
#pos = nx.random_layout(G)
# rendering
plt.figure(1)
plt.subplot(211); plt.axis('off')
nx.draw_networkx_nodes(G, pos)
nx.draw_networkx_edges(G, pos, width=edgewidth,)
plt.subplot(212); plt.axis('off')
# rendering
nx.draw_networkx_nodes(G, pos)
nx.draw_networkx_edges(G, pos, edge_color=edgewidth)
plt.show()
Run Code Online (Sandbox Code Playgroud)
这给你这样的东西: 
显然,您可以使用更复杂的函数来组合适合您的应用程序的edgewidth值列表(例如,分箱值或不同属性的产品).