方法四:利用pyecharts实现图展示-保存为html
1.利用echart进行实现,利用网页形式,在web前端显示图形,让后利用echart获得后台的数据
2.需要工具,echart,flask
3.pip install echarts
4.保存为gif
① 1.如果想直接将图片保存为 png, pdf, gif 格式的文件,可以使用 pyecharts-snapshot。使用该插件请确保你的系统上已经安装了 Nodejs 环境。
② 安装 phantomjs $ npm install -g phantomjs-prebuilt
③ 安装 pyecharts-snapshot $ pip install pyecharts-snapshot
④ 调用 render 方法 bar.render(path='snapshot.png') 文件结尾可以为 svg/jpeg/png/pdf/gif。请注意,svg 文件需要你在初始化 bar 的时候设置 renderer='svg'。
5.首先利用pyecharts画一个静态的图形
#http://pyecharts.org/#/zh-cn/prepare帮助文件
from
pyecharts
import
Line
import
numpy
as
np
x=list(range(0,50))
y1=list(np.random.random(50))
y2=list(np.random.random(50))
y2=[m/2
for
m
in
y2
if
m>0]#for的迭代式式,加过滤器if,生产list
line=Line(
"折线图"
)
line.add("A",x,y1,mark_point=["average"],line_width=3,line_color="red")line.add("B",x,y2,mark_point=["average"],line_width=3,line_color="blue")#line.show_config()
line.render(
"myechart001.html"
)#生成html文件
import
webbrowser
webbrowser.open(
"myechart001.html"
)#