【发布时间】:2017-04-19 07:53:27
【问题描述】:
我知道之前有人问过类似的问题,但我的问题有点复杂。我正在尝试根据它们的出度来定义networkx图的节点大小,但是会有些混乱。这是我的代码:
nodes = pd.read_csv('nodes_1984.csv')
edges = pd.read_csv('edges_1984.csv')
nodes.head()
this how my data containing nodes looks like (click)
network=nx.DiGraph()
for row in nodes.iterrows():
network.add_node(row[1][0], Label=row[1][1], region=row[1][2], pos=(row[1][4], row[1][3]))
for row in edges.iterrows():
network.add_edge(row[1][0],row[1][1], weight=row[1][3])
pos=nx.get_node_attributes(network,'pos')
d_out = network.out_degree() #dictionary of {nodes:out_degree_values}
d_out_val = [] #creating a list which contains values of out_degree of nodes and sorting them in the same order as they were in the d_out dict
for w in sorted(d_out.keys()):
d_out_val.append(d_out[w])
d_out_val
plt.figure(figsize=(32,28)) #plotting my network
nx.draw(network, pos, with_labels=True, node_size=[s * 100 for s in d_out_val], node_color="w")
plt.show()
结果是我在图中节点的大小与这些节点的出度值不对应,尽管我在上面对包含节点度值的列表 (d_out_val) 进行了排序。 你能告诉我这个问题可以解决什么吗?
【问题讨论】:
标签: python python-2.7 networkx