python pyecharts 数据可视化展示

2022/1/25 20:06:50

本文主要是介绍python pyecharts 数据可视化展示,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

from pyecharts import options as opts
from snapshot_selenium import snapshot as driver

    def draw_chart(self, file, save_path):
        """
        前端回放性能用例数据统计图
        file: excel完整路径
        save_path: html 和 png 保存目录
        """
        data = pandas.read_excel(file, engine='openpyxl')
        shape = data.shape
        nrows = shape[0]
        ncols = shape[1]
        # print(f'当前总计行数:' + str(nrows))  # 获取行数
        # print(f'当前总计列数:' + str(ncols))  # 获取列数

        dt_dates = []  # 日期
        dt_avg_fpss = []  # 平均帧率
        dt_fat_fps_nums = []  # 肥胖帧个数

        for i in range(nrows):
            dt_date = data.iloc[i, 0]
            dt_dates.append(dt_date)

            dt_avg_fps = data.iloc[i, 1]
            dt_avg_fpss.append(float(dt_avg_fps))

            dt_fat_fps_num = data.iloc[i, 2]
            dt_fat_fps_nums.append(float(dt_fat_fps_num))

        # print(dt_fat_fps_nums)
        line = (
            Line(init_opts=opts.InitOpts(width='1850px', height='640px'))
                .add_xaxis(dt_dates)
                .add_yaxis("平均帧率", dt_avg_fpss)
                .add_yaxis("肥胖帧个数", dt_fat_fps_nums)
                .set_global_opts(title_opts=opts.TitleOpts(title="前端性能测试情况"))
        )
        line.set_series_opts(
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_='average', name='平均值'),
                    opts.MarkPointItem(type_='max', name='最大值'),
                    opts.MarkPointItem(type_='min', name='最小值')
                ]
            )

        )

        # 设置标题等
        line.set_global_opts(title_opts=opts.TitleOpts('前端性能跟踪变化曲线'),
                             # 显示工具箱
                             toolbox_opts=opts.ToolboxOpts(),
                             xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45, "interval": 0})
                             )

        file_name = self.getTestCaseName(file)
        html_name = file_name + ".html"
        html_save_path = save_path + "\\" + html_name
        line.render(html_save_path)
        snapshot_save_path = save_path + "\\bar.png"
        # 需要安装 snapshot-selenium 或者 snapshot-phantomjs
        make_snapshot(driver, line.render(), snapshot_save_path)
        # webbrowser.open(html_name)



这篇关于python pyecharts 数据可视化展示的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程