桑基图还是很简单的,直接调用pyecharts就行,套用我的代码即可实现。
注意:1.节点名称唯一。
2.关系用的节点必须是已经创建的。
首先上效果图:
代码如下:
#coding='utf-8'
from pyecharts import options as opts
from pyecharts.charts import Sankey
#问题是节点名称不能一样
#所有关键词和主题词是节点,然后在同一年份的目标指向是主题词;主题词间又根据时间进行指向
#更新:四个关键词为一行,一个主题词为一行,间隔一行为年
nodes=[ # 所有节点名称
#关键词,使用后缀无空格代表15-16,后缀一个空格代表17-18,后缀两个空格代表19-20
{"name": "图书馆"},{"name": "数字"},{"name": "资源"},{"name": "互联网"},
{"name": "大数据"},{"name": "突发事件"},{"name": "政府"},{"name": "媒体"},
{"name": "文献整理"},{"name": "数字化"},{"name": "口述资料"},{"name": "古籍"},
{"name": "数字资源"},{"name": "版权"},{"name": "作品"},{"name": "语义"},
{"name": "知识"},{"name": "信息熵"},{"name": "产业链"},{"name": "关联数据"},
{"name": "阅读推广"},{"name": "农民工"},{"name": "公民"},{"name": "满意度"},
#15-16
{"name": "图书馆 "},{"name": "阅读 "},{"name": "信息服务 "},{"name": "公共 "},
{"name": "知识 "},{"name": "科学 "},{"name": "大数据 "},{"name": "专利 "},
{"name": "文献 "},{"name": "文化遗产 "},{"name": "医药 "},{"name": "数字化 "},
{"name": "文献整理 "},{"name": "出土 "},{"name": "藏文 "},{"name": "佛教 "},
{"name": "科技馆 "},{"name": "科学素养 "},{"name": "档案 "},{"name": "保障体系 "},
{"name": "数字人文 "},{"name": "扶贫 "},{"name": "西北 "},{"name": "贫困 "},
#17-18
{"name": "档案 "},{"name": "公共卫生 "},{"name": "在线健康社区 "},{"name": "大数据 "},
{"name": "文献整理 "},{"name": "出土 "},{"name": "史料 "},{"name": "民间 "},
{"name": "图书馆 "},{"name": "公共图书馆 "},{"name": "阅读推广 "},{"name": "知识服务 "},
{"name": "数据库 "},{"name": "知识流动 "},{"name": "科技成果 "},{"name": "转化 "},
{"name": "情报 "},{"name": "知识图谱 "},{"name": "突发事件 "},{"name": "危机 "},
{"name": "学术论文 "},{"name": "科研人员 "},{"name": "学术交流 "},{"name": "知识 "},
#19-20 over
#主题词 start
{"name": "图书馆建设"},
{"name": "大数据舆情"},
{"name": "文献数字化"},
{"name": "知识产权"},
{"name": "数据科学"},
{"name": "信息服务"},
#15-16over
{"name": "图书馆建设 "},
{"name": "大数据科研 "},
{"name": "文献数字化 "},
{"name": "古籍文献整理 "},
{"name": "信息素养教育 "},
{"name": "信息扶贫 "},
#17-18over
{"name": "大数据健康 "},
{"name": "古籍文献整理 "},
{"name": "信息服务 "},
{"name": "信息产业 "},
{"name": "大数据舆情 "},
{"name": "数据科学 "},
#19-20 over
]
links = [ # 每一条链路的数据,包含:父节点source + 子节点target + 数据值value(根据权重*100不四舍五入)
#一年的——两年链接——新一年的
#第一年的关键词需要链接后两年的
#先将1年的关键词连接到对应的主题词,然后匹配下一年对应的关键词,接着关键词继续链接到对应的主题词
{"source": "图书馆", "target": "图书馆建设", "value": 3},
{"source": "数字", "target": "图书馆建设", "value": 1},
{"source": "资源", "target": "图书馆建设", "value": 2},
{"source": "互联网", "target": "图书馆建设", "value": 1},
{"source": "大数据", "target": "大数据舆情", "value": 2},
{"source": "突发事件", "target": "大数据舆情", "value": 2},
{"source": "政府", "target": "大数据舆情", "value": 1},
{"source": "媒体", "target": "大数据舆情", "value": 1},
{"source": "文献整理", "target": "文献数字化", "value": 3},
{"source": "数字化", "target": "文献数字化", "value": 2},
{"source": "口述资料", "target": "文献数字化", "value": 1},
{"source": "古籍", "target": "文献数字化", "value": 2},
{"source": "数字资源", "target": "知识产权", "value": 1},
{"source": "版权", "target": "知识产权", "value": 2},
{"source": "作品", "target": "知识产权", "value": 1},
{"source": "语义", "target": "知识产权", "value": 1},
{"source": "知识", "target": "数据科学", "value": 2},
{"source": "信息熵", "target": "数据科学", "value": 1},
{"source": "产业链", "target": "数据科学", "value": 1},
{"source": "关联数据", "target": "数据科学", "value": 1},
{"source": "阅读推广", "target": "信息服务", "value": 2},
{"source": "农民工", "target": "信息服务", "value": 1},
{"source": "公民", "target": "信息服务", "value": 2},
{"source": "满意度", "target": "信息服务", "value": 1},#15-16关键词链接到主题词
#15-16主题词连接到17-18关键词,同时需要15-16主题词链接到19-20关键词
{"source": "图书馆建设", "target": "图书馆 ", "value": 3},
{"source": "图书馆建设", "target": "图书馆 ", "value": 6},
{"source": "大数据舆情", "target": "大数据 ", "value": 4},
{"source": "大数据舆情", "target": "大数据 ", "value": 3},
{"source": "大数据舆情", "target": "突发事件 ", "value": 2},
{"source": "文献数字化", "target": "文献整理 ", "value": 4},
{"source": "文献数字化", "target": "数字化 ", "value": 1},
{"source": "文献数字化", "target": "文献整理 ", "value": 1},
{"source": "数据科学", "target": "知识 ", "value": 3},
{"source": "数据科学", "target": "知识 ", "value": 3},
{"source": "信息服务", "target": "阅读推广 ", "value": 2},
#开始将17-18年关键词链接到当年主题词
{"source": "图书馆 ", "target": "图书馆建设 ", "value": 6},
{"source": "阅读 ", "target": "图书馆建设 ", "value": 2},
{"source": "信息服务 ", "target": "图书馆建设 ", "value": 1},
{"source": "公共 ", "target": "图书馆建设 ", "value": 1},
{"source": "知识 ", "target": "大数据科研 ", "value": 3},
{"source": "科学 ", "target": "大数据科研 ", "value": 2},
{"source": "大数据 ", "target": "大数据科研 ", "value": 4},
{"source": "专利 ", "target": "大数据科研 ", "value": 1},
{"source": "文献 ", "target": "文献数字化 ", "value": 4},
{"source": "文化遗产 ", "target": "文献数字化 ", "value": 1},
{"source": "医药 ", "target": "文献数字化 ", "value": 1},
{"source": "数字化 ", "target": "文献数字化 ", "value": 2},
{"source": "文献整理 ", "target": "古籍文献整理 ", "value": 4},
{"source": "出土 ", "target": "古籍文献整理 ", "value": 1},
{"source": "藏文 ", "target": "古籍文献整理 ", "value": 1},
{"source": "佛教 ", "target": "古籍文献整理 ", "value": 1},
{"source": "科技馆 ", "target": "信息素养教育 ", "value": 2},
{"source": "科学素养 ", "target": "信息素养教育 ", "value": 3},
{"source": "档案 ", "target": "信息素养教育 ", "value": 1},
{"source": "保障体系 ", "target": "信息素养教育 ", "value": 1},
{"source": "数字人文 ", "target": "信息扶贫 ", "value": 1},
{"source": "扶贫 ", "target": "信息扶贫 ", "value": 2},
{"source": "西北 ", "target": "信息扶贫 ", "value": 1},
{"source": "贫困 ", "target": "信息扶贫 ", "value": 1},
#17-18主题词连接到19-20关键词
{"source": "图书馆建设 ", "target": "图书馆 ", "value": 3},
{"source": "大数据科研 ", "target": "大数据 ", "value": 3},
{"source": "大数据科研 ", "target": "知识 ", "value": 1},
{"source": "古籍文献整理 ", "target": "文献整理 ", "value": 4},
{"source": "古籍文献整理 ", "target": "出土 ", "value": 1},
{"source": "信息素养教育 ", "target": "档案 ", "value": 1},
#开始将19-20年关键词链接到当年主题词
{"source": "档案 ", "target": "大数据健康 ", "value": 3},
{"source": "公共卫生 ", "target": "大数据健康 ", "value": 2},
{"source": "在线健康社区 ", "target": "大数据健康 ", "value": 1},
{"source": "大数据 ", "target": "大数据健康 ", "value": 3},
{"source": "文献整理 ", "target": "古籍文献整理 ", "value": 4},
{"source": "出土 ", "target": "古籍文献整理 ", "value": 1},
{"source": "史料 ", "target": "古籍文献整理 ", "value": 1},
{"source": "民间 ", "target": "古籍文献整理 ", "value": 2},
{"source": "图书馆 ", "target": "信息服务 ", "value": 3},
{"source": "公共图书馆 ", "target": "信息服务 ", "value": 2},
{"source": "阅读推广 ", "target": "信息服务 ", "value": 2},
{"source": "知识服务 ", "target": "信息服务 ", "value": 1},
{"source": "数据库 ", "target": "信息产业 ", "value": 4},
{"source": "知识流动 ", "target": "信息产业 ", "value": 2},
{"source": "科技成果 ", "target": "信息产业 ", "value": 2},
{"source": "转化 ", "target": "信息产业 ", "value": 1},
{"source": "情报 ", "target": "大数据舆情 ", "value": 5},
{"source": "知识图谱 ", "target": "大数据舆情 ", "value": 3},
{"source": "突发事件 ", "target": "大数据舆情 ", "value": 3},
{"source": "危机 ", "target": "大数据舆情 ", "value": 1},
{"source": "学术论文 ", "target": "数据科学 ", "value": 3},
{"source": "科研人员 ", "target": "数据科学 ", "value": 3},
{"source": "学术交流 ", "target": "数据科学 ", "value": 1},
{"source": "知识 ", "target": "数据科学 ", "value": 1},
]
c = (
Sankey()
.add(
"",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
)
.set_global_opts(title_opts=opts.TitleOpts(title="主题演化"))
)
c.render("主题演化.html") #生成HTML文件