pyecharts 桑基图 节点位置 调整 对应pyecharts2.x版本
时间: 2023-11-15 14:07:08 浏览: 46
在 pyecharts 2.x 版本中,可以通过 `graph.add()` 方法的 `layout` 参数来调整桑基图节点的位置。
具体来说,可以将节点的位置通过一个字典传入 `layout` 参数中,字典的 key 为节点的名称,value 为节点的位置信息,如下所示:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [{"name": "node1"}, {"name": "node2"}, {"name": "node3"}]
links = [{"source": "node1", "target": "node2", "value": 10},
{"source": "node2", "target": "node3", "value": 20}]
sankey = Sankey().add("sankey", nodes, links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="source"),
label_opts=opts.LabelOpts(position="right"),
tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove|click"),
layout={
"node1": {"x": 100, "y": 50},
"node2": {"x": 300, "y": 100},
"node3": {"x": 500, "y": 150}
}
)
sankey.render("sankey.html")
```
上面的例子中,我们通过 `layout` 参数将节点1的位置设为 (100, 50),节点2的位置设为 (300, 100),节点3的位置设为 (500, 150)。
需要注意的是,在 pyecharts 2.x 版本中,节点位置的坐标系是以左上角为原点的,即 x 轴向右,y 轴向下。因此,节点的位置信息应该按照这个坐标系来设置。