pyecharts桑基图边颜色设置
时间: 2023-09-20 09:06:21 浏览: 51
在 Pyecharts 中,可以通过 `set_edge_item` 方法来设置桑基图的边的颜色。具体来说,可以通过以下代码来实现:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
sankey = Sankey()
nodes = [
{"name": "a"},
{"name": "b"},
{"name": "c"},
{"name": "d"},
{"name": "e"}
]
links = [
{"source": "a", "target": "b", "value": 10},
{"source": "b", "target": "c", "value": 15},
{"source": "c", "target": "d", "value": 20},
{"source": "d", "target": "e", "value": 25}
]
sankey.add(
series_name="",
nodes=nodes,
links=links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5, width=10),
label_opts=opts.LabelOpts(position="right"),
).set_global_opts(
title_opts=opts.TitleOpts(title="Sankey Diagram"),
tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove"),
).set_series_opts(
label_opts=opts.LabelOpts(position="right"),
# 设置边颜色
linestyle_opts=opts.LineStyleOpts(color="#333", opacity=0.8, curve=0.5, width=10)
)
sankey.render("sankey.html")
```
其中,`linestyle_opts` 参数可以用来设置边的样式,包括颜色、透明度、曲度和宽度等。在这里,我们将边的颜色设置为 `#333`。
阅读全文