pyecharts桑基图代码
时间: 2023-11-22 08:46:40 浏览: 101
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
# 构造数据
nodes = [
{"name": "A"},
{"name": "B"},
{"name": "C"},
{"name": "D"},
{"name": "E"},
{"name": "F"},
]
links = [
{"source": "A", "target": "B", "value": 10},
{"source": "A", "target": "C", "value": 15},
{"source": "B", "target": "D", "value": 12},
{"source": "C", "target": "D", "value": 5},
{"source": "D", "target": "E", "value": 8},
{"source": "D", "target": "F", "value": 10},
]
# 绘制桑基图
sankey = (
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 Diagram"))
)
# 保存图表
sankey.render("sankey.html")
```
阅读全文