pyecharts桑基图节点颜色
时间: 2023-09-24 22:07:40 浏览: 59
JavaFX 绘制桑基图(SankeyDiagram)
要设置桑基图节点的颜色,可以在 `Sankey.add` 方法中通过参数 `node_color` 来指定节点的颜色。例如:
```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": "D", "target": "E", "value": 20}
]
sankey = Sankey()
sankey.add(
"sankey",
nodes,
links,
node_gap=30,
node_width=20,
node_label_opts=opts.LabelOpts(position="right"),
linestyle_opt=opts.LineStyleOpts(opacity=0.2),
label_opts=opts.LabelOpts(font_size=14),
node_color=["#FFB6C1", "#87CEFA", "#90EE90", "#FFC0CB", "#ADD8E6"]
)
sankey.render("sankey.html")
```
在 `node_color` 参数中传入一个列表,每个元素对应一个节点的颜色,节点的顺序与传入的 `nodes` 列表一致。
阅读全文