网络编程
位置:首页>> 网络编程>> Python编程>> 通过Python pyecharts输出保存图片代码实例

通过Python pyecharts输出保存图片代码实例

作者:-零  发布时间:2021-09-14 22:26:11 

标签:Python,pyecharts,输出,图片

安装pyecharts:pip install pyecharts

安装snapshot-selenium:pip install snapshot-selenium

安装ChromeDriver:下载地址

注意:下载和电脑上的谷歌浏览器版本相同或者相近的版本,将ChromeDriver.exe放到项目文件所在文件夹即可。

通过Python pyecharts输出保存图片代码实例

代码示例


from pyecharts.charts import Bar
from pyecharts import options as opts

# 导入输出图片工具
from pyecharts.render import make_snapshot
# 使用snapshot-selenium 渲染图片
from snapshot_selenium import snapshot

# 创建一个柱状图Bar实例

bar = (
 Bar()
 # 添加X轴数据
 .add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
 # 添加Y轴数据,系列的名称
 .add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
 .add_yaxis("商家B", [8, 15, 60, 20, 25, 30])
 # 添加标题
 .set_global_opts(title_opts=opts.TitleOpts(title="主标题: 双十一销量", subtitle="副标题:服饰类"))
)

# 输出保存为图片
make_snapshot(snapshot, bar.render(), "Options配置项_自定义样式_保存图片.png")

来源:https://www.cnblogs.com/-wenli/p/14024078.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com