社交网络(social network):几个著名的社交网络。
1)karate_club_graph() 空手道俱乐部 | 返回 Zachary’s karate club graph |
2)davis_southern_women_graph() | Returns Davis Southern women social network |
3)florentine_families_graph() | Returns Florentine families graph |
4)Les_miserables_graph() | Returns coappearance network of characters in the novel les miserable |
1. network.generators.social.karate_club_graph
karate_club_graph()
returns Zachary’s karate club graph. 返回扎卡利的空手道俱乐部
返回的图中的每一个节点有一个“club”属性,表明该节点代表的成员是属于哪个俱乐部的,或者是“Mr Hi”,或者是“Officer”。
得到一个节点所属的俱乐部:
import networkx as nximport pandas as pdimport matplotlib.pyplot as pltG=nx.karate_club_graph()G.nodes[5]['club']
Out[26]: 'Mr. Hi'
G.nodes[9]['club']
Out[27]: 'Officer'
G1 = nx.davis_southern_women_graph()nodecolor=pd.DataFrame(G1.degree()).iloc[:,1]edgecolor=range(G1.number_of_edges())nx.draw(G1,with_labels=True, node_size=nodecolor*30,node_color=nodecolor*10, edge_color=edgecolor,node_cmap=plt.cm.Blues)
2. networkx.genertors.social.davis_southern_women_graph
davis_southern_women_graph()
Returns Davis southern women social network.
这是一个二分图(bipartite graph)
G2 = nx.florentine_families_graph()nodecolor=pd.DataFrame(G2.degree()).iloc[:,1]edgecolor=range(G2.number_of_edges())nx.draw(G2,with_labels=True, node_size=nodecolor*30,node_color=nodecolor*10, edge_color=edgecolor,node_cmap=plt.cm.Blues)
3. networkx.generators.social.florentine_families_graph
Florentine_families_graph()
返回佛罗伦萨家庭图
4. networkx.generators.social.les_miserables_graph
les_miserables_graph()
返回小说《悲惨世界》人物网络
总结:
Number of nodes | Number of edges | |
karate_club_graph() | 34 | 78 |
davis_southern_women_graph() | 32 | 89 |
Florentine_families_graph() | 15 | 20 |
les_miserables_graph() | 77 | 254 |