【发布时间】:2021-07-15 08:10:57
【问题描述】:
我要做的是使用 NetworkX 库计算度中心性,然后根据此度量更改不同节点的颜色和大小。
预期的结果是让节点根据其度中心性显示为不同的颜色和大小,但目前,它们只显示默认颜色,因为我不知道我应该这样做。
我在这个项目中使用的 csv 文件可以在这里找到。 https://www.mediafire.com/file/q0kziy9h251fcjf/nutrients.csv/file
该文件目前没有错误消息,除了颜色大小没有改变。
我目前尝试考虑做某种列表理解来解决问题,但我还不确定如何去做,或者如何设置颜色图(什么颜色不重要)
这是我目前正在使用的代码。
import networkx as nx
import matplotlib.pyplot as plt
Data = open('nutrients.csv', "r")
next(Data, None)
Graph_type = nx.Graph()
G = nx.parse_edgelist(Data, delimiter=',', create_using=Graph_type,
nodetype=str, data=(('weight', float),))
deg_centrality = nx.degree_centrality(G)
print(deg_centrality)
pos = nx.spring_layout(G)
nx.draw(G, pos)
plt.show()
H
【问题讨论】:
标签: python python-3.x matplotlib graph networkx