pyecharts桑基图link颜色设置
时间: 2023-10-09 10:17:41 浏览: 135
你可以使用 `visualmap` 来设置桑基图的颜色。
下面是一个示例代码:
```python
from pyecharts import options as opts
from pyecharts.charts import Sankey
nodes = [
{"name": "category1"},
{"name": "category2"},
{"name": "category3"},
{"name": "category4"},
{"name": "category5"},
{"name": "category6"}
]
links = [
{"source": "category1", "target": "category2", "value": 10},
{"source": "category2", "target": "category3", "value": 15},
{"source": "category3", "target": "category4", "value": 20},
{"source": "category4", "target": "category5", "value": 25},
{"source": "category5", "target": "category6", "value": 30}
]
sankey = Sankey()
sankey.add(
series_name="",
nodes=nodes,
links=links,
linestyle_opt=opts.LineStyleOpts(opacity=0.2),
label_opts=opts.LabelOpts(position="right"),
# 设置颜色
visualmap_opts=opts.VisualMapOpts(
orient="horizontal",
pos_left="10",
pos_top="10",
min_=10,
max_=30,
range_text=["High", "Low"],
dimension=0,
# 设置颜色范围
range_color=["lightskyblue", "yellow", "orangered"]
)
)
sankey.render("sankey.html")
```
运行以上代码,你可以得到一个带有渐变颜色的桑基图。你可以根据需要调整 `range_color` 参数来设置颜色范围。
阅读全文