pyecharts桑基图指定节点颜色
时间: 2023-09-20 22:06:21 浏览: 99
获取指定点颜色
在Pyecharts中设置桑基图节点的颜色可以使用visualmap组件来实现。可以通过以下代码指定颜色:
```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": 30},
{"source": "B", "target": "C", "value": 20}]
color_list = ["#C23531", "#2F4554", "#61A0A8"]
sankey = 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=13),
node_gap=25,
layout_iterations=32,
is_draggable=True,
tooltip_opts=opts.TooltipOpts(trigger_on="mousemove|click", is_show=True),
visualmap_opts=opts.VisualMapOpts(is_show=True, min_=0, max_=50, range_text=['High', 'Low'],
range_color=color_list))
sankey.render("sankey.html")
```
在上述代码中,`color_list`是一个节点颜色列表,包含了需要设置的颜色值。在`visualmap_opts`中使用`range_color`参数将颜色列表传入,即可实现指定节点颜色的效果。
阅读全文