https://gallery.pyecharts.org/#/Sankey/sankey_base
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_notebook()
# .render("sankey_base.html")
)
c.render_notebook()
<script>
require.config({
paths: {
'echarts':'https://assets.pyecharts.org/assets/echarts.min'
}
});
</script>
<div id="f4229f0479084dcca6d227ed9f2f5e78" style="width:900px; height:500px;"></div>
<script>
require(['echarts'], function(echarts) {
var chart_f4229f0479084dcca6d227ed9f2f5e78 = echarts.init(
document.getElementById('f4229f0479084dcca6d227ed9f2f5e78'), 'white', {renderer: 'canvas'});
var option_f4229f0479084dcca6d227ed9f2f5e78 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"color": [
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597"
],
"series": [
{
"type": "sankey",
"name": "sankey",
"data": [
{
"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
}
],
"left": "5%",
"top": "5%",
"right": "20%",
"bottom": "5%",
"nodeWidth": 20,
"nodeGap": 8,
"nodeAlign": "justify",
"layoutIteration": 32,
"orient": "horizontal",
"draggable": true,
"focusNodeAdjacency": false,
"label": {
"show": true,
"position": "right",
"margin": 8
},
"lineStyle": {
"show": true,
"width": 1,
"opacity": 0.2,
"curveness": 0.5,
"type": "solid",
"color": "source"
}
}
],
"legend": [
{
"data": [
"sankey"
],
"selected": {
"sankey": true
},
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5
},
"title": [
{
"text": "Sankey-\u57fa\u672c\u793a\u4f8b",
"padding": 5,
"itemGap": 10
}
]
};
chart_f4229f0479084dcca6d227ed9f2f5e78.setOption(option_f4229f0479084dcca6d227ed9f2f5e78);
});
</script>