pyecharts桑基图节点颜色
时间: 2023-09-18 19:16:21 浏览: 164
在pyecharts中,可以通过 `Node.color` 属性来设置桑基图节点的颜色。以下是一个简单的示例代码:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "A"},
{"name": "B"},
{"name": "C"},
{"name": "D"},
]
links = [
{"source": "A", "target": "B", "value": 10},
{"source": "B", "target": "C", "value": 15},
{"source": "C", "target": "D", "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", font_size=12),
node_gap=20, node_width=25,
)
.set_global_opts(title_opts=opts.TitleOpts(title="Basic Sankey Diagram"))
)
# 设置节点颜色
sankey.nodes[0].color = "#FF0000"
sankey.nodes[1].color = "#00FF00"
sankey.nodes[2].color = "#0000FF"
sankey.nodes[3].color = "#FF00FF"
sankey.render("sankey.html")
```
在上面的代码中,我们设置了每个节点的颜色,分别为红色、绿色、蓝色和紫色。可以根据实际需求调整节点颜色。
阅读全文