说说使用上的三点注意:
1.nodes中的"name"不要重新命名,否则会不识别,导致没有图
2.links中source和target对应的值一定要在nodes的name对应的值中,否则图中会不显示(但是不会报错)
3.links中source和target对应的值不能相同,否则图不显示
主要参考: 桑基图官方文档
# official
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category5", "target": "category6", "value": 25},
]
c = (
Sankey()
.add(
"sankey",
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="Sankey-基本示例"))
.render("sankey_base.html")
)
参考1:Pyecharts 1.7.0制作图表,运行生成的html文件用浏览器打开空白问题(以桑基图为例)
主要用于无法访问html中的"https://assets.pyecharts.org/assets/echarts.min.js",可在无法联网时使用
方法为:手动定制下载echarts.min.js,复制到本地,然后修改.html文件 “https://assets.pyecharts.org/assets/echarts.min.js"为相对路径”./echarts.min.js"