import networkx as nx
import numpy as np
import random
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
%matplotlib inline
plt.rcParams["font.sans-serif"]=["SimHei"]
plt.rcParams["axes.unicode_minus"]=False
df = pd.read_csv("xyj/triples.csv")
df
head | tail | relation | label | |
---|---|---|---|---|
0 | 金蝉子 | 唐僧 | past_life | 前世 |
1 | 孙悟空 | 唐僧 | apprentice | 徒弟 |
2 | 猪八戒 | 唐僧 | apprentice | 徒弟 |
3 | 沙僧 | 唐僧 | apprentice | 徒弟 |
4 | 白龙马 | 唐僧 | apprentice | 徒弟 |
... | ... | ... | ... | ... |
104 | 毗蓝婆菩萨 | 昴日星官 | mother | 母亲 |
105 | 嫦娥 | 后羿 | wife | 妻 |
106 | 敖摩昂 | 敖闰 | son | 儿 |
107 | 哪吒 | 李靖 | son | 儿 |
108 | 哪吒 | 如来 | apprentice | 徒弟 |
109 rows × 4 columns
edges = [*zip(df["head"], df["tail"])]
G = nx.DiGraph()
G.add_edges_from(edges)
print(G)
DiGraph with 104 nodes and 109 edges
G.nodes
NodeView(('金蝉子', '唐僧', '孙悟空', '猪八戒', '沙僧', '白龙马', '陈光蕊', '殷温娇', '法明和尚', '李世民', '殷开山', '菩提老祖', '镇元子', '牛魔王', '蛟魔王', '鹏魔王', '狮驼王', '猕猴王', '禺狨王', '天蓬元帅', '卵二姐', '高翠兰', '卷帘大将', '西海龙王', '西海龙母', '敖摩昂太子', '西海龙女', '李渊', '李建成', '李元吉', '王珪', '秦琼', '萧瑀', '傅奕', '魏征', '李玉英', '房玄龄', '杜如晦', '徐世绩', '徐茂公', '许敬宗', '马三宝', '段志贤', '程咬金', '虞世南', '张道源', '张士衡', '高太公', '高香兰', '高玉兰', '寇洪', '寇梁', '宼栋', '袁守诚', '袁天罡', '李靖', '木吒', '哪吒', '金吒', '正元龙', '观音菩萨', '二十四路诸天', '守山大神', '善财童子', '捧珠龙女', '如来', '红孩儿', '黑风怪', '黄风怪', '灵吉菩萨', '黄毛貂鼠', '金角', '太上老君', '银角', '铁扇公主', '九尾狐狸', '狐阿七', '鼍龙怪', '西海龙王太子', '灵感大王', '独角兕大王', '玉面公主', '金毛犼', '黄眉道童', '弥勒佛', '百眼魔君', '毗蓝婆菩萨', '青狮', '文殊菩萨', '白象', '普贤菩萨', '大鹏金翅雕', '九头狮子', '太乙救苦天尊', '玉兔精', '嫦娥', '白鹿精', '南极寿星', '黄眉大王', '东来佛祖笑和尚', '昴日星官', '后羿', '敖摩昂', '敖闰'))
len(G)
104
plt.figure(figsize=(15,14))
pos = nx.spring_layout(G, iterations=3, seed=5)
nx.draw(G, pos, with_labels=True)
plt.show()
pagerank = nx.pagerank(G,
alpha=0.85,
personalization=None,
max_iter=100,
tol=1e-06,
nstart=None,
dangling=None
)
pagerank
{'金蝉子': 0.0028889203144616088,
'唐僧': 0.13349105557884888,
'孙悟空': 0.10498354112014094,
'猪八戒': 0.09247797536009736,
'沙僧': 0.07627154154696374,
'白龙马': 0.09531260474698808,
'陈光蕊': 0.0028889203144616088,
'殷温娇': 0.005344620286308959,
'法明和尚': 0.0028889203144616088,
'李世民': 0.052002919751408624,
'殷开山': 0.0028889203144616088,
'菩提老祖': 0.0028889203144616088,
'镇元子': 0.0028889203144616088,
'牛魔王': 0.010256020230003658,
'蛟魔王': 0.0028889203144616088,
'鹏魔王': 0.0028889203144616088,
'狮驼王': 0.0028889203144616088,
'猕猴王': 0.0028889203144616088,
'禺狨王': 0.0028889203144616088,
'天蓬元帅': 0.0028889203144616088,
'卵二姐': 0.01860884001045803,
'高翠兰': 0.02579183411604112,
'卷帘大将': 0.0028889203144616088,
'西海龙王': 0.0028889203144616088,
'西海龙母': 0.0028889203144616088,
'敖摩昂太子': 0.0028889203144616088,
'西海龙女': 0.0028889203144616088,
'李渊': 0.0028889203144616088,
'李建成': 0.0028889203144616088,
'李元吉': 0.0028889203144616088,
'王珪': 0.0028889203144616088,
'秦琼': 0.0028889203144616088,
'萧瑀': 0.0028889203144616088,
'傅奕': 0.0028889203144616088,
'魏征': 0.0028889203144616088,
'李玉英': 0.0028889203144616088,
'房玄龄': 0.0028889203144616088,
'杜如晦': 0.0028889203144616088,
'徐世绩': 0.0028889203144616088,
'徐茂公': 0.0028889203144616088,
'许敬宗': 0.0028889203144616088,
'马三宝': 0.0028889203144616088,
'段志贤': 0.0028889203144616088,
'程咬金': 0.0028889203144616088,
'虞世南': 0.0028889203144616088,
'张道源': 0.0028889203144616088,
'张士衡': 0.0028889203144616088,
'高太公': 0.0028889203144616088,
'高香兰': 0.0028889203144616088,
'高玉兰': 0.004116770300385284,
'寇洪': 0.0028889203144616088,
'寇梁': 0.005344620286308959,
'宼栋': 0.007432108638238391,
'袁守诚': 0.0028889203144616088,
'袁天罡': 0.005344620286308959,
'李靖': 0.006787403654483575,
'木吒': 0.004812288400108432,
'哪吒': 0.009171370913926254,
'金吒': 0.004812288400108432,
'正元龙': 0.0028889203144616088,
'观音菩萨': 0.026625716774094633,
'二十四路诸天': 0.0028889203144616088,
'守山大神': 0.0028889203144616088,
'善财童子': 0.0028889203144616088,
'捧珠龙女': 0.0028889203144616088,
'如来': 0.013334300311185142,
'红孩儿': 0.0028889203144616088,
'黑风怪': 0.0028889203144616088,
'黄风怪': 0.0028889203144616088,
'灵吉菩萨': 0.007800320258156309,
'黄毛貂鼠': 0.0028889203144616088,
'金角': 0.005344620286308959,
'太上老君': 0.014430996933862522,
'银角': 0.005344620286308959,
'铁扇公主': 0.0028889203144616088,
'九尾狐狸': 0.0028889203144616088,
'狐阿七': 0.0028889203144616088,
'鼍龙怪': 0.0028889203144616088,
'西海龙王太子': 0.005344620286308959,
'灵感大王': 0.0028889203144616088,
'独角兕大王': 0.0028889203144616088,
'玉面公主': 0.0028889203144616088,
'金毛犼': 0.0028889203144616088,
'黄眉道童': 0.0028889203144616088,
'弥勒佛': 0.005344620286308959,
'百眼魔君': 0.0028889203144616088,
'毗蓝婆菩萨': 0.005344620286308959,
'青狮': 0.0028889203144616088,
'文殊菩萨': 0.005344620286308959,
'白象': 0.0028889203144616088,
'普贤菩萨': 0.005344620286308959,
'大鹏金翅雕': 0.0028889203144616088,
'九头狮子': 0.0028889203144616088,
'太乙救苦天尊': 0.005344620286308959,
'玉兔精': 0.0028889203144616088,
'嫦娥': 0.005344620286308959,
'白鹿精': 0.0028889203144616088,
'南极寿星': 0.005344620286308959,
'黄眉大王': 0.0028889203144616088,
'东来佛祖笑和尚': 0.005344620286308959,
'昴日星官': 0.007432108638238391,
'后羿': 0.007432108638238391,
'敖摩昂': 0.0028889203144616088,
'敖闰': 0.005344620286308959}
sorted(pagerank.items(), key=lambda x:x[1], reverse=True)
[('唐僧', 0.13349105557884888),
('孙悟空', 0.10498354112014094),
('白龙马', 0.09531260474698808),
('猪八戒', 0.09247797536009736),
('沙僧', 0.07627154154696374),
('李世民', 0.052002919751408624),
('观音菩萨', 0.026625716774094633),
('高翠兰', 0.02579183411604112),
('卵二姐', 0.01860884001045803),
('太上老君', 0.014430996933862522),
('如来', 0.013334300311185142),
('牛魔王', 0.010256020230003658),
('哪吒', 0.009171370913926254),
('灵吉菩萨', 0.007800320258156309),
('宼栋', 0.007432108638238391),
('昴日星官', 0.007432108638238391),
('后羿', 0.007432108638238391),
('李靖', 0.006787403654483575),
('殷温娇', 0.005344620286308959),
('寇梁', 0.005344620286308959),
('袁天罡', 0.005344620286308959),
('金角', 0.005344620286308959),
('银角', 0.005344620286308959),
('西海龙王太子', 0.005344620286308959),
('弥勒佛', 0.005344620286308959),
('毗蓝婆菩萨', 0.005344620286308959),
('文殊菩萨', 0.005344620286308959),
('普贤菩萨', 0.005344620286308959),
('太乙救苦天尊', 0.005344620286308959),
('嫦娥', 0.005344620286308959),
('南极寿星', 0.005344620286308959),
('东来佛祖笑和尚', 0.005344620286308959),
('敖闰', 0.005344620286308959),
('木吒', 0.004812288400108432),
('金吒', 0.004812288400108432),
('高玉兰', 0.004116770300385284),
('金蝉子', 0.0028889203144616088),
('陈光蕊', 0.0028889203144616088),
('法明和尚', 0.0028889203144616088),
('殷开山', 0.0028889203144616088),
('菩提老祖', 0.0028889203144616088),
('镇元子', 0.0028889203144616088),
('蛟魔王', 0.0028889203144616088),
('鹏魔王', 0.0028889203144616088),
('狮驼王', 0.0028889203144616088),
('猕猴王', 0.0028889203144616088),
('禺狨王', 0.0028889203144616088),
('天蓬元帅', 0.0028889203144616088),
('卷帘大将', 0.0028889203144616088),
('西海龙王', 0.0028889203144616088),
('西海龙母', 0.0028889203144616088),
('敖摩昂太子', 0.0028889203144616088),
('西海龙女', 0.0028889203144616088),
('李渊', 0.0028889203144616088),
('李建成', 0.0028889203144616088),
('李元吉', 0.0028889203144616088),
('王珪', 0.0028889203144616088),
('秦琼', 0.0028889203144616088),
('萧瑀', 0.0028889203144616088),
('傅奕', 0.0028889203144616088),
('魏征', 0.0028889203144616088),
('李玉英', 0.0028889203144616088),
('房玄龄', 0.0028889203144616088),
('杜如晦', 0.0028889203144616088),
('徐世绩', 0.0028889203144616088),
('徐茂公', 0.0028889203144616088),
('许敬宗', 0.0028889203144616088),
('马三宝', 0.0028889203144616088),
('段志贤', 0.0028889203144616088),
('程咬金', 0.0028889203144616088),
('虞世南', 0.0028889203144616088),
('张道源', 0.0028889203144616088),
('张士衡', 0.0028889203144616088),
('高太公', 0.0028889203144616088),
('高香兰', 0.0028889203144616088),
('寇洪', 0.0028889203144616088),
('袁守诚', 0.0028889203144616088),
('正元龙', 0.0028889203144616088),
('二十四路诸天', 0.0028889203144616088),
('守山大神', 0.0028889203144616088),
('善财童子', 0.0028889203144616088),
('捧珠龙女', 0.0028889203144616088),
('红孩儿', 0.0028889203144616088),
('黑风怪', 0.0028889203144616088),
('黄风怪', 0.0028889203144616088),
('黄毛貂鼠', 0.0028889203144616088),
('铁扇公主', 0.0028889203144616088),
('九尾狐狸', 0.0028889203144616088),
('狐阿七', 0.0028889203144616088),
('鼍龙怪', 0.0028889203144616088),
('灵感大王', 0.0028889203144616088),
('独角兕大王', 0.0028889203144616088),
('玉面公主', 0.0028889203144616088),
('金毛犼', 0.0028889203144616088),
('黄眉道童', 0.0028889203144616088),
('百眼魔君', 0.0028889203144616088),
('青狮', 0.0028889203144616088),
('白象', 0.0028889203144616088),
('大鹏金翅雕', 0.0028889203144616088),
('九头狮子', 0.0028889203144616088),
('玉兔精', 0.0028889203144616088),
('白鹿精', 0.0028889203144616088),
('黄眉大王', 0.0028889203144616088),
('敖摩昂', 0.0028889203144616088)]
node_size = (np.array([*pagerank.values()]) * 8000).astype(int)
node_size
array([ 23, 1067, 839, 739, 610, 762, 23, 42, 23, 416, 23,
23, 23, 82, 23, 23, 23, 23, 23, 23, 148, 206,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 32, 23, 42, 59, 23, 42,
54, 38, 73, 38, 23, 213, 23, 23, 23, 23, 106,
23, 23, 23, 62, 23, 42, 115, 42, 23, 23, 23,
23, 42, 23, 23, 23, 23, 23, 42, 23, 42, 23,
42, 23, 42, 23, 23, 42, 23, 42, 23, 42, 23,
42, 59, 59, 23, 42])
M = G.number_of_edges()
edge_colors = range(2, M + 2)
plt.figure(figsize=(15,14))
nodes = nx.draw_networkx_nodes(G, pos, node_size=node_size, node_color=node_size)
edges = nx.draw_networkx_edges(G,
pos,
node_size=node_size,
arrowstyle="->",
arrowsize=20,
edge_color=edge_colors,
edge_cmap=plt.cm.plasma,
width=4
)
edge_alphas = [*map(lambda x:(5 + x) / (M + 4), range(M))]
for i in range(M):
edges[i].set_alpha(edge_alphas[i])
ax = plt.gca()
ax.set_axis_off()
plt.show()
df = pd.read_csv("sgyy/triples.csv")
df
head | tail | relation | label | |
---|---|---|---|---|
0 | 关羽 | 刘备 | younger_sworn_brother | 义弟 |
1 | 张飞 | 刘备 | younger_sworn_brother | 义弟 |
2 | 关羽 | 张飞 | elder_sworn_brother | 义兄 |
3 | 张苞 | 张飞 | son | 儿子 |
4 | 关兴 | 关羽 | son | 儿子 |
... | ... | ... | ... | ... |
148 | 曹植 | 曹丕 | younger_brother | 弟弟 |
149 | 马谡 | 诸葛亮 | colleague | 同事 |
150 | 马谡 | 刘备 | minister | 臣 |
151 | 孙坚 | 孙权 | father | 父亲 |
152 | 吴国太 | 孙权 | mother | 母亲 |
153 rows × 4 columns
edges = [*zip(df["head"], df["tail"])]
G = nx.DiGraph()
G.add_edges_from(edges)
print(G)
DiGraph with 123 nodes and 144 edges
G.nodes
NodeView(('关羽', '刘备', '张飞', '张苞', '关兴', '关平', '卢植', '公孙瓒', '甘氏', '刘禅', '诸葛瞻', '诸葛亮', '姜维', '黄月英', '黄承彦', '诸葛瑾', '公孙越', '马超', '马腾', '韩遂', '徐庶', '曹操', '刘胜', '刘启', '刘辩', '孙权', '孙尚香', '糜氏', '糜芳', '糜竺', '魏延', '赵云', '黄忠', '庞统', '法正', '蒋琬', '马良', '孟获', '沙摩柯', '庞德公', '马谡', '祝融', '孙韶', '孙策', '孙氏', '陆逊', '刘协', '董卓', '王允', '貂蝉', '吕布', '丁原', '高顺', '陈宫', '张辽', '刘表', '蔡氏', '蔡瑁', '蒯越', '黄祖', '文聘', '张宝', '张角', '张梁', '袁绍', '袁术', '袁谭', '袁熙', '袁尚', '吴国太', '孙坚', '大乔', '小乔', '周瑜', '丁奉', '徐盛', '鲁肃', '张昭', '蒋钦', '太史慈', '周泰', '凌统', '吕蒙', '甘宁', '黄盖', '韩当', '程普', '曹嵩', '吕伯奢', '邹氏', '张绣', '清河公主', '夏侯楙', '夏侯渊', '夏侯淳', '曹真', '曹爽', '郭嘉', '徐晃', '乐进', '张郃', '许褚', '典韦', '荀彧', '荀攸', '贾诩', '司马懿', '程昱', '于禁', '邓艾', '钟会', '庞德', '司马师', '司马昭', '司马炎', '曹仁', '曹纯', '曹昂', '刘氏', '超昂', '卞氏', '曹丕', '曹植'))
len(G)
123
plt.figure(figsize=(15,14))
pos = nx.spring_layout(G, iterations=3, seed=5)
nx.draw(G, pos, with_labels=True)
plt.show()
pagerank = nx.pagerank(G,
alpha=0.85,
personalization=None,
max_iter=100,
tol=1e-06,
nstart=None,
dangling=None
)
pagerank
{'关羽': 0.007648261820990993,
'刘备': 0.04316090803062529,
'张飞': 0.010684617486214243,
'张苞': 0.004790628403339912,
'关兴': 0.0033618116945143706,
'关平': 0.0033618116945143706,
'卢植': 0.0033618116945143706,
'公孙瓒': 0.006219445112165452,
'甘氏': 0.007433987378254753,
'刘禅': 0.004790628403339912,
'诸葛瞻': 0.0033618116945143706,
'诸葛亮': 0.07948672044565522,
'姜维': 0.07332434279539564,
'黄月英': 0.006219445112165452,
'黄承彦': 0.0033618116945143706,
'诸葛瑾': 0.004315323462283846,
'公孙越': 0.0033618116945143706,
'马超': 0.011094431736222054,
'马腾': 0.006219445112165452,
'韩遂': 0.0033618116945143706,
'徐庶': 0.007197559170724445,
'曹操': 0.03760593503605732,
'刘胜': 0.0033618116945143706,
'刘启': 0.026390485738599024,
'刘辩': 0.02372935636421138,
'孙权': 0.0190692623269325,
'孙尚香': 0.0033618116945143706,
'糜氏': 0.012495057895261747,
'糜芳': 0.010744484610898969,
'糜竺': 0.00580771378639237,
'魏延': 0.00580771378639237,
'赵云': 0.00580771378639237,
'黄忠': 0.00580771378639237,
'庞统': 0.008665347204043453,
'法正': 0.00580771378639237,
'蒋琬': 0.00580771378639237,
'马良': 0.006760258258942731,
'孟获': 0.008665347204043453,
'沙摩柯': 0.00580771378639237,
'庞德公': 0.0033618116945143706,
'马谡': 0.0033618116945143706,
'祝融': 0.0033618116945143706,
'孙韶': 0.0033618116945143706,
'孙策': 0.01257039701604605,
'孙氏': 0.0033618116945143706,
'陆逊': 0.009712763598394968,
'刘协': 0.023960679808974043,
'董卓': 0.0033618116945143706,
'王允': 0.004790628403339912,
'貂蝉': 0.0033618116945143706,
'吕布': 0.009077078529816533,
'丁原': 0.0033618116945143706,
'高顺': 0.005933745855183798,
'陈宫': 0.005933745855183798,
'张辽': 0.0073235912395158715,
'刘表': 0.012571335953525803,
'蔡氏': 0.01083424156046205,
'蔡瑁': 0.008790721626177701,
'蒯越': 0.004751657078846445,
'黄祖': 0.006923864976600935,
'文聘': 0.006923864976600935,
'张宝': 0.006219445112165452,
'张角': 0.00864852964434405,
'张梁': 0.0033618116945143706,
'袁绍': 0.013570983766541082,
'袁术': 0.0033618116945143706,
'袁谭': 0.00864852964434405,
'袁熙': 0.006219445112165452,
'袁尚': 0.0033618116945143706,
'吴国太': 0.004790628403339912,
'孙坚': 0.01608320021921716,
'大乔': 0.009337535871422605,
'小乔': 0.007029980145397405,
'周瑜': 0.004315323462283846,
'丁奉': 0.004315323462283846,
'徐盛': 0.004315323462283846,
'鲁肃': 0.004315323462283846,
'张昭': 0.004315323462283846,
'蒋钦': 0.004315323462283846,
'太史慈': 0.004315323462283846,
'周泰': 0.004315323462283846,
'凌统': 0.004315323462283846,
'吕蒙': 0.004315323462283846,
'甘宁': 0.004315323462283846,
'黄盖': 0.004315323462283846,
'韩当': 0.004315323462283846,
'程普': 0.004315323462283846,
'曹嵩': 0.006219445112165452,
'吕伯奢': 0.0033618116945143706,
'邹氏': 0.0033618116945143706,
'张绣': 0.0061804737876719855,
'清河公主': 0.007936127771473664,
'夏侯楙': 0.005381343968179999,
'夏侯渊': 0.004751657078846445,
'夏侯淳': 0.006771189352512074,
'曹真': 0.007609290496497527,
'曹爽': 0.0033618116945143706,
'郭嘉': 0.004751657078846445,
'徐晃': 0.004751657078846445,
'乐进': 0.004751657078846445,
'张郃': 0.004751657078846445,
'许褚': 0.004751657078846445,
'典韦': 0.004751657078846445,
'荀彧': 0.004751657078846445,
'荀攸': 0.008790721626177701,
'贾诩': 0.004751657078846445,
'司马懿': 0.012499602089774645,
'程昱': 0.004751657078846445,
'于禁': 0.004751657078846445,
'邓艾': 0.004751657078846445,
'钟会': 0.004751657078846445,
'庞德': 0.004751657078846445,
'司马师': 0.0060051706694292115,
'司马昭': 0.006219445112165452,
'司马炎': 0.0033618116945143706,
'曹仁': 0.006219445112165452,
'曹纯': 0.0033618116945143706,
'曹昂': 0.0033618116945143706,
'刘氏': 0.006219445112165452,
'超昂': 0.0033618116945143706,
'卞氏': 0.00864852964434405,
'曹丕': 0.006219445112165452,
'曹植': 0.0033618116945143706}
sorted(pagerank.items(), key=lambda x:x[1], reverse=True)
[('诸葛亮', 0.07948672044565522),
('姜维', 0.07332434279539564),
('刘备', 0.04316090803062529),
('曹操', 0.03760593503605732),
('刘启', 0.026390485738599024),
('刘协', 0.023960679808974043),
('刘辩', 0.02372935636421138),
('孙权', 0.0190692623269325),
('孙坚', 0.01608320021921716),
('袁绍', 0.013570983766541082),
('刘表', 0.012571335953525803),
('孙策', 0.01257039701604605),
('司马懿', 0.012499602089774645),
('糜氏', 0.012495057895261747),
('马超', 0.011094431736222054),
('蔡氏', 0.01083424156046205),
('糜芳', 0.010744484610898969),
('张飞', 0.010684617486214243),
('陆逊', 0.009712763598394968),
('大乔', 0.009337535871422605),
('吕布', 0.009077078529816533),
('蔡瑁', 0.008790721626177701),
('荀攸', 0.008790721626177701),
('庞统', 0.008665347204043453),
('孟获', 0.008665347204043453),
('张角', 0.00864852964434405),
('袁谭', 0.00864852964434405),
('卞氏', 0.00864852964434405),
('清河公主', 0.007936127771473664),
('关羽', 0.007648261820990993),
('曹真', 0.007609290496497527),
('甘氏', 0.007433987378254753),
('张辽', 0.0073235912395158715),
('徐庶', 0.007197559170724445),
('小乔', 0.007029980145397405),
('黄祖', 0.006923864976600935),
('文聘', 0.006923864976600935),
('夏侯淳', 0.006771189352512074),
('马良', 0.006760258258942731),
('公孙瓒', 0.006219445112165452),
('黄月英', 0.006219445112165452),
('马腾', 0.006219445112165452),
('张宝', 0.006219445112165452),
('袁熙', 0.006219445112165452),
('曹嵩', 0.006219445112165452),
('司马昭', 0.006219445112165452),
('曹仁', 0.006219445112165452),
('刘氏', 0.006219445112165452),
('曹丕', 0.006219445112165452),
('张绣', 0.0061804737876719855),
('司马师', 0.0060051706694292115),
('高顺', 0.005933745855183798),
('陈宫', 0.005933745855183798),
('糜竺', 0.00580771378639237),
('魏延', 0.00580771378639237),
('赵云', 0.00580771378639237),
('黄忠', 0.00580771378639237),
('法正', 0.00580771378639237),
('蒋琬', 0.00580771378639237),
('沙摩柯', 0.00580771378639237),
('夏侯楙', 0.005381343968179999),
('张苞', 0.004790628403339912),
('刘禅', 0.004790628403339912),
('王允', 0.004790628403339912),
('吴国太', 0.004790628403339912),
('蒯越', 0.004751657078846445),
('夏侯渊', 0.004751657078846445),
('郭嘉', 0.004751657078846445),
('徐晃', 0.004751657078846445),
('乐进', 0.004751657078846445),
('张郃', 0.004751657078846445),
('许褚', 0.004751657078846445),
('典韦', 0.004751657078846445),
('荀彧', 0.004751657078846445),
('贾诩', 0.004751657078846445),
('程昱', 0.004751657078846445),
('于禁', 0.004751657078846445),
('邓艾', 0.004751657078846445),
('钟会', 0.004751657078846445),
('庞德', 0.004751657078846445),
('诸葛瑾', 0.004315323462283846),
('周瑜', 0.004315323462283846),
('丁奉', 0.004315323462283846),
('徐盛', 0.004315323462283846),
('鲁肃', 0.004315323462283846),
('张昭', 0.004315323462283846),
('蒋钦', 0.004315323462283846),
('太史慈', 0.004315323462283846),
('周泰', 0.004315323462283846),
('凌统', 0.004315323462283846),
('吕蒙', 0.004315323462283846),
('甘宁', 0.004315323462283846),
('黄盖', 0.004315323462283846),
('韩当', 0.004315323462283846),
('程普', 0.004315323462283846),
('关兴', 0.0033618116945143706),
('关平', 0.0033618116945143706),
('卢植', 0.0033618116945143706),
('诸葛瞻', 0.0033618116945143706),
('黄承彦', 0.0033618116945143706),
('公孙越', 0.0033618116945143706),
('韩遂', 0.0033618116945143706),
('刘胜', 0.0033618116945143706),
('孙尚香', 0.0033618116945143706),
('庞德公', 0.0033618116945143706),
('马谡', 0.0033618116945143706),
('祝融', 0.0033618116945143706),
('孙韶', 0.0033618116945143706),
('孙氏', 0.0033618116945143706),
('董卓', 0.0033618116945143706),
('貂蝉', 0.0033618116945143706),
('丁原', 0.0033618116945143706),
('张梁', 0.0033618116945143706),
('袁术', 0.0033618116945143706),
('袁尚', 0.0033618116945143706),
('吕伯奢', 0.0033618116945143706),
('邹氏', 0.0033618116945143706),
('曹爽', 0.0033618116945143706),
('司马炎', 0.0033618116945143706),
('曹纯', 0.0033618116945143706),
('曹昂', 0.0033618116945143706),
('超昂', 0.0033618116945143706),
('曹植', 0.0033618116945143706)]
node_size = (np.array([*pagerank.values()]) * 8000).astype(int)
node_size
array([ 61, 345, 85, 38, 26, 26, 26, 49, 59, 38, 26, 635, 586,
49, 26, 34, 26, 88, 49, 26, 57, 300, 26, 211, 189, 152,
26, 99, 85, 46, 46, 46, 46, 69, 46, 46, 54, 69, 46,
26, 26, 26, 26, 100, 26, 77, 191, 26, 38, 26, 72, 26,
47, 47, 58, 100, 86, 70, 38, 55, 55, 49, 69, 26, 108,
26, 69, 49, 26, 38, 128, 74, 56, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 49, 26, 26, 49,
63, 43, 38, 54, 60, 26, 38, 38, 38, 38, 38, 38, 38,
70, 38, 99, 38, 38, 38, 38, 38, 48, 49, 26, 49, 26,
26, 49, 26, 69, 49, 26])
M = G.number_of_edges()
edge_colors = range(2, M + 2)
plt.figure(figsize=(15,14))
nodes = nx.draw_networkx_nodes(G, pos, node_size=node_size, node_color=node_size)
edges = nx.draw_networkx_edges(G,
pos,
node_size=node_size,
arrowstyle="->",
arrowsize=20,
edge_color=edge_colors,
edge_cmap=plt.cm.plasma,
width=4
)
edge_alphas = [*map(lambda x:(5 + x) / (M + 4), range(M))]
for i in range(M):
edges[i].set_alpha(edge_alphas[i])
ax = plt.gca()
ax.set_axis_off()
plt.show()