pyecharts桑基图指定节点颜色
时间: 2023-09-20 13:06:18 浏览: 53
你可以通过设置 `visualmap` 来指定桑基图中节点的颜色,示例如下:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "A"},
{"name": "B"},
{"name": "C"},
{"name": "D"},
{"name": "E"},
]
links = [
{"source": "A", "target": "B", "value": 10},
{"source": "A", "target": "C", "value": 15},
{"source": "B", "target": "D", "value": 12},
{"source": "C", "target": "D", "value": 8},
{"source": "C", "target": "E", "value": 5},
]
color = ['#003366', '#006699', '#4cabce', '#e5323e', '#f29c9f']
sankey = (
Sankey()
.add(
"sankey",
nodes,
links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5),
label_opts=opts.LabelOpts(position="right"),
color=color,
)
.set_global_opts(
title_opts=opts.TitleOpts(title="Sankey Diagram"),
visualmap_opts=opts.VisualMapOpts(
orient="horizontal",
pos_left="10",
pos_top="10",
max_=20,
min_=0,
range_text=["High", "Low"],
dimension=0,
range_color=color,
),
)
)
sankey.render_notebook()
```
在上述代码中,我们通过 `color` 参数设置了每个节点的颜色,然后在 `add()` 方法中通过 `color` 参数将颜色应用到节点上。此外,我们还设置了 `visualmap` 来显示节点颜色的范围,并在 `set_global_opts()` 中指定了 `visualmap_opts` 参数。
阅读全文