pyecharts桑基图边颜色设置
时间: 2023-09-20 13:07:28 浏览: 146
JavaFX 绘制桑基图(SankeyDiagram)
pyecharts桑基图(Sankey)的边颜色可以通过`set_edge_color()`方法来设置。该方法接受三个参数:
- source_node:源节点名称
- target_node:目标节点名称
- color:颜色值,支持十六进制和颜色名称
示例代码:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "A"},
{"name": "B"},
{"name": "C"}
]
links = [
{"source": "A", "target": "B", "value": 20},
{"source": "B", "target": "C", "value": 10},
{"source": "A", "target": "C", "value": 30}
]
sankey = (
Sankey()
.add("sankey", nodes, links, linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, color="#bbb"))
.set_global_opts(title_opts=opts.TitleOpts(title="Sankey"))
.set_series_opts(label_opts=opts.LabelOpts(font_size=12))
)
# 设置边颜色
sankey.set_edge_color("A", "B", "red")
sankey.set_edge_color("B", "C", "blue")
sankey.set_edge_color("A", "C", "green")
sankey.render("sankey.html")
```
运行以上代码,会生成一个名为`sankey.html`的HTML文件,打开即可看到结果。
阅读全文