当前位置: 首页 > 工具软件 > 折线图Demo > 使用案例 >

Pyecharts折线图绘制以及图片生成

呼延沈义
2023-12-01
# -*- coding: utf-8 -*-

import xlrd
import numpy as np
import pandas as pd
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.charts import Line
from pyecharts.charts import Sankey
from pyecharts.render import make_snapshot
from snapshot_selenium import snapshot

excel_data = pd.read_excel("data1.xls")
l = (
    Line(init_opts=opts.InitOpts(width='7000px', height='400px'))
    .add_xaxis(xaxis_data=excel_data["time"].tolist())
    .add_yaxis(series_name='2020', y_axis=excel_data["2020data"].tolist())


    .add_yaxis(series_name='2021', y_axis=excel_data["2021data"].tolist())
    .add_yaxis(series_name='2022', y_axis=excel_data["2022data"].tolist())
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(
            name='time',
            name_location='middle',
            name_gap=1,
            name_textstyle_opts=opts.TextStyleOpts(
                font_family='Times New Roman',
                font_size=15,
            ),
        ),
        yaxis_opts=opts.AxisOpts(
            name='Daily_Data',
            name_location='middle',
            name_gap=50,
            name_textstyle_opts=opts.TextStyleOpts(
                font_family='Times New Roman',
                font_size=15,
            ),
            axistick_opts=opts.AxisTickOpts(
                is_inside=True,  
            ),
            axislabel_opts=opts.LabelOpts(
                font_size=12,
                font_family='Times New Roman',
            ),
        ),

    )
)
l.render("data.html")

make_snapshot(snapshot,l.render(), "data.png")

 类似资料: