pyecharts桑基图布局调整
时间: 2023-09-20 11:07:29 浏览: 76
Pyecharts 的桑基图默认布局是水平布局,如果需要调整布局,可以使用 `orient` 参数来设置为垂直布局。
例如,以下代码是一个水平布局的桑基图:
``` python
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category4", "target": "category5", "value": 25},
]
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-Horizontal"))
)
sankey.render("sankey_horizontal.html")
```
如果要将其改为垂直布局,只需在 `Sankey` 类的参数中加入 `orient="vertical"`,如下:
``` python
sankey = (
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
orient="vertical", # 垂直布局
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-Vertical"))
)
```
然后再次运行代码即可得到垂直布局的桑基图。
阅读全文