pyecharts设置背景图片
时间: 2023-10-03 09:10:57 浏览: 205
可以使用渐变色作为背景,代码如下:
```
from pyecharts.charts import Line
from pyecharts import options as opts
line = Line()
line.add_xaxis(['Jan', 'Feb', 'Mar', 'Apr', 'May'])
line.add_yaxis('Sales', [120, 200, 150, 80, 70])
line.set_global_opts(
title_opts={"text": "Sales Trend"},
graphic_opts=[
opts.GraphicImage(
graphic_item=opts.GraphicItem(
id_="logo",
right=20,
top=20,
z=10,
bounding="raw",
origin=[75, 75],
),
graphic_imagestyle_opts=opts.GraphicImageStyleOpts(
image="https://s3.ax1x.com/2020/11/05/BW8Vvq.jpg", # 背景图片链接
width=150,
height=150,
opacity=0.8,
),
),
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="center", top="center", z=100
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=800, height=350
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="rgba(0,0,0,0.3)"
),
),
],
)
line.render('line.html')
```
其中,`graphic_imagestyle_opts` 中 `image` 参数可以设置背景图片的链接。另外,还可以通过 `graphic_basicstyle_opts` 设定渐变色的透明度、颜色等参数。
阅读全文