pyecharts 桑基图 节点位置 调整 对应pyecharts2.0.3版本
时间: 2023-11-15 20:13:22 浏览: 22
在 Pyecharts 2.0.3 版本中,可以通过 `sankey_node_pos` 参数来调整桑基图中节点的位置。
示例代码:
```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": "category1", "target": "category3", "value": 20},
{"source": "category1", "target": "category4", "value": 30},
{"source": "category2", "target": "category4", "value": 15},
{"source": "category2", "target": "category5", "value": 5},
{"source": "category3", "target": "category4", "value": 25},
{"source": "category3", "target": "category5", "value": 15},
{"source": "category4", "target": "category5", "value": 20},
]
node_pos = [
{"name": "category1", "x": 100, "y": 100},
{"name": "category2", "x": 300, "y": 100},
{"name": "category3", "x": 300, "y": 300},
{"name": "category4", "x": 500, "y": 50},
{"name": "category5", "x": 500, "y": 250},
]
sankey = (
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
node_gap=10,
sankey_node_width=20,
sankey_node_gap=10,
sankey_node_pos=node_pos,
)
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey-基本示例"))
)
sankey.render("sankey_node_pos.html")
```
在 `node_pos` 列表中,每个节点的位置可以通过 `x` 和 `y` 参数来指定。可以根据需要修改节点的位置,然后运行代码即可生成调整后的桑基图。
相关推荐
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)