栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Pyecharts可视化分析图表

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Pyecharts可视化分析图表

简介

Pyecharts是一个用于生成Echarts图表的类库。Echarts是百度开源的一个数据可视化JS库。

用Echarts生成的图可视化效果非常好,而Pyecharts则是专门为了与Python衔接,方便在Python中直接使用的可视化数据分析图表。使用Pyecharts可以生成独立的网页格式的图表,还可以在flask、django中直接使用,非常方便

Pyecharts的图表类型非常多且效果非常漂亮

安装

pip install pyecharts

查看是否安装成功:

pip show pyecharts

Pyecharts图表的组成

主要包括风格的设置,提示框,视觉映射,工具箱和区域缩放

绘制第一张图表 步骤如下:

(1)从pyecharts.charts库中导入Bar模块

from pyecharts.charts import Bar

(2)从pyecharts库中导入options模块

from pyecharts import options as opts

(3)从pyecharts.globals库中导入主题类型模块ThemeType

from pyecharts.globals import ThemeType

(4)设置画布大小、图表主题和图表背景颜色

(5)渲染图表到HTML文件中,并存放在程序所在目录下,存放的是我们html文件的名称,然后打开html页面,就可以看到效果

也可以直接查看效果,使用bar.render_notebook()

代码展示
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
bar=(
    Bar(init_opts=opts.InitOpts(
#         设置画布
        width='500px',height='300px',
#         设置主题
        theme=ThemeType.WONDERLAND,
#         背景颜色
        bg_color='#fff'))
    .add_xaxis(['1月','2月','3月','4月','5月','7月'])
    .add_yaxis('零基础雪python',[2345,2323,5342,1355,3452,4365])
    .add_yaxis('python趣味案例编程',[2324,1224,5463,2342,2453,3521])
    .set_global_opts(
#         添加图表标题
        title_opts=opts.TitleOpts(
            "热门图书销量分析",
#             padding=[2,0,5,90],
            subtitle="www.mingrisoft.com",
            item_gap=5,
#             主标题文字样式配置项,颜色、字体样式、字体的粗细、字体的大小以及对齐方式等
            title_textstyle_opts=opts.TextStyleOpts(color='blue',
                                                    font_size=18),
            title_link='https://www.baidu.com/' #主标题跳转url链接
        ),
#         添加图例
        legend_opts=opts.LegendOpts(
            pos_right=50,
            item_width=45,
            legend_icon='circle'
        ),
#         添加提示框
        tooltip_opts=opts.TooltipOpts(
            trigger='axis',
            trigger_on='click',
            axis_pointer_type='cross',
            background_color='pink',
            border_width=2,
            border_color='black'
        ),
#         视觉映射
        visualmap_opts=opts.VisualMapOpts(
            type_='size',
            orient='vertical',
            pos_left='right',
            min_=1,
            max_=6000,
            range_text=['max','min'],
            range_color=['#FFF0F5','#8B008B']
        )
    )
)
# 渲染图表到html文件中
bar.render('mycharts.html')
bar.render_notebook()

效果展示

图表风格的设置,提示框,视觉映射,工具箱和区域缩放的参数具体查看官网

pyecharts - A Python Echarts Plotting Library built with love.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/958629.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号