Code:[ZachxPKU/NetworkSciencewithPythonandNetworkXQuickStartGuide]
Chapter 2 Working with Networks in NetworkX
- The Graph class
- Attributes
- Edge weights
- The DiGRaph class
- The MultiGraph and MultiDiGraph classes
The Graph class - undirected networks
Adding attributes to nodes and edges
本节当中有一些示例代码存在错误,具体如下:
node_colors = [
'#1f78b4' if G.nodes[v]["club"] == 0
else '#33a02c' for v in G]
nx.draw_networkx(G, karate_pos, label=True, node_color=node_color)
应该为:
node_colors = [
'#1f78b4' if G.nodes[v]["club"] == 0
else '#33a02c' for v in G]
nx.draw_networkx(G, karate_pos, label=True, node_color=node_colors)
Adding edge weights
The DiGraph class - when direction matters
本节当中有一些示例代码存在错误,具体如下:
G = nx.read_gexf("../data/knecht2008/klas12b-net-1.gexf")
student_pos = nx.spring_layout(G, k = 1.5)
nx.draw_networkx(G, pos, arrowsize = 20)
应该为:
G = nx.read_gexf("../data/knecht2008/klas12b-net-1.gexf")
student_pos = nx.spring_layout(G, k = 1.5)
nx.draw_networkx(G, student_pos, arrowsize = 20)
list(G.neighbors(0))
应该为
list(G.neighbors('0‘))