pyecharts桑基图边颜色设置
时间: 2023-09-25 12:11:28 浏览: 82
在 Pyecharts 中,桑基图的边颜色可以通过设置 `sankey_links` 中的 `line_style` 参数实现。具体操作如下:
1. 定义节点和边的数据:
```python
nodes = [
{"name": "A"},
{"name": "B"},
{"name": "C"},
{"name": "D"},
{"name": "E"}
]
links = [
{"source": "A", "target": "B", "value": 10, "color": "#f00"},
{"source": "A", "target": "D", "value": 5, "color": "#0f0"},
{"source": "B", "target": "C", "value": 7, "color": "#00f"},
{"source": "C", "target": "D", "value": 8, "color": "#f0f"},
{"source": "D", "target": "E", "value": 3, "color": "#ff0"}
]
```
其中,`color` 参数用于定义边的颜色。
2. 创建桑基图并设置边颜色:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
sankey = Sankey()
sankey.add(
series_name="",
nodes=nodes,
links=links,
label_opts=opts.LabelOpts(position="right"),
itemstyle_opts=opts.ItemStyleOpts(border_color="#aaa", border_width=0.5),
linestyle_opt=opts.LineStyleOpts(opacity=0.2, curve=0.5),
sankey_layout="none",
)
sankey.set_global_opts(
title_opts=opts.TitleOpts(title="Sankey Diagram"),
tooltip_opts=opts.TooltipOpts(trigger="item", trigger_on="mousemove|click"),
)
sankey.render("sankey.html")
```
在 `links` 中定义的边数据中,通过 `color` 参数设置了边的颜色。然后在 `sankey.add()` 方法中,通过 `itemstyle_opts` 参数设置边的样式,其中 `border_color` 参数用于设置边的颜色,`border_width` 参数用于设置边的宽度。
注意:Pyecharts 版本需要在 v1.7.0 以上才支持桑基图边颜色的设置。
阅读全文
相关推荐














