pyecharts 气泡图 涟漪特效
时间: 2023-07-09 07:47:32 浏览: 82
好的,关于 pyecharts 的气泡图涟漪特效,您可以参考以下代码实现:
```python
from pyecharts.charts import Scatter
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
# 数据
data = [
[10.0, 8.04, 10.0],
[8.0, 6.95, 8.0],
[13.0, 7.58, 13.0],
[9.0, 8.81, 9.0],
[11.0, 8.33, 11.0],
[14.0, 9.96, 14.0],
[6.0, 7.24, 6.0],
[4.0, 4.26, 4.0],
[12.0, 10.84, 12.0],
[7.0, 4.82, 7.0],
[5.0, 5.68, 5.0]
]
# 构建图表
scatter = (
Scatter()
.add_xaxis([d[0] for d in data])
.add_yaxis("", [d[1] for d in data])
.set_series_opts(
label_opts=opts.LabelOpts(formatter=JsCode("function(params){return params.value[2];}"))
)
.set_global_opts(
title_opts=opts.TitleOpts(title="气泡图涟漪特效"),
visualmap_opts=opts.VisualMapOpts(type_="size", max_=15, min_=2),
xaxis_opts=opts.AxisOpts(type_="value"),
yaxis_opts=opts.AxisOpts(type_="value"),
tooltip_opts=opts.TooltipOpts(
formatter=JsCode(
"function (params) {return params.value[2] + ' : ' + params.value[1] + '<br/>' + params.value[0] + ' : ' + params.value[3];}"
)
),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(
# 设置涟漪效果
type_="circle",
shape="pin",
# 设置大小和颜色
style_opts=opts.GraphicItemStyleOpts(
stroke="#fff",
lineWidth=0,
fill="#e60000",
opacity=0.7
),
# 设置涟漪效果
ripple_effect=opts.RippleEffectOpts(
period=4,
scale=6,
brush_type="stroke",
),
),
# 设置涟漪效果的位置和大小
position=[10, 10],
# 设置涟漪效果的大小
bounding="raw",
)
],
)
)
# 渲染图表
scatter.render("bubble_chart.html")
```
运行代码后,会生成一个名为 `bubble_chart.html` 的 HTML 文件,打开即可看到气泡图涟漪特效的可视化效果。