美文网首页
颜值爆表的数据可视化库--Pyecharts

颜值爆表的数据可视化库--Pyecharts

作者: EvanLX | 来源:发表于2018-12-17 13:50 被阅读0次

    最近发现一个颜值爆表的数据可视化库,

    简单易上手的同时功能非常强大,

    以下是柱状图、折线图、环形饼图的基本示例,

    跟网上其他示例不同的是,我用了一些个性化表达的通用配置,

    例如x轴标签设置旋转角度、折线图平滑曲线、图例显示或隐藏、自定义显示系列名等。

    使用Jupyter Notebook编程工具,

    本文源代码地址:https://download.csdn.net/download/s34855/10855445

    pyecharts详细的使用文档地址:http://pyecharts.org/#/zh-cn/


    柱状图

    from pyecharts import Bar  # 导入柱状图-Bar
    
    # 横纵坐标
    columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    # 设置数据
    data1 = [200, 500, 80, 230, 300, 700, 200, 100, 500, 600, 700, 300]
    data2 = [250, 500, 900, 260, 280, 400, 180, 150, 500, 220, 300, 200]
    # 设置柱状图的主标题与副标题
    bar = Bar("柱状图", "年收入与支出")
    # 添加柱状图的数据及配置项
    # mark_point,标记点,默认有'min', 'max', 'average'可选。表达最值
    # legend_orient,图例列表的布局朝向,有'horizontal', 'vertical'可选,默认 -> 'horizontal'
    # legend_pos,图例组件离容器左侧的距离,有'left', 'center', 'right'可选,也可以为百分数,如"%60",默认 -> 'center'
    bar.add("收入", columns, data1, mark_line=["average"], mark_point=["max", "min"],legend_orient='vertical',legend_pos='right')
    bar.add("支出", columns, data2, mark_line=["average"], mark_point=["max", "min"],legend_orient='vertical',legend_pos='right')
    # 生成本地文件(默认为.html文件,根目录)
    bar.render()
    bar  # 在jupyter notebook显示图表 
    
    柱状图Bar.png

    折线图

    from pyecharts import Line  # 导入折线图-Line
    
    line = Line("折线图", "每周销售量", width=1200, height=400)
    attr = ['8.3-8.9','8.10-8.16','8.16-8.22','8.23-8.29','8.30-9.5','9.6-9.12','9.13-9.19','9.20-9.26']
    data = [12000,22000,21000,29000,35000,26000,26000,23000]
    # mark_line=["average"]趋势线
    # is_label_show=True显示数据标签
    # x轴标签设置旋转角度xaxis_rotate
    # legend_pos,图例组件离容器左侧的距离,有'left', 'center', 'right'可选
    # is_smooth -> bool,是否平滑曲线显示,默认为 False
    line.add("销售量",attr,data, is_label_show=True,legend_orient='vertical',legend_pos='center', is_smooth=True, xaxis_rotate='30')
    # 指定生成html文件
    line.render(r"C:\Programming\Python3\Test\每周销售量折线图.html")
    line  # 在jupyter notebook显示图表 
    
    折线图Line.png

    环形饼图

    from pyecharts import Pie  # 导入饼图-Pie
    
    attr = ["蔬菜","水果","肉品","零食","饮料"]
    data = [14,10,13,309,200]
    pie = Pie("环形饼图", "商品种类", title_pos='center_left')
    # legend_orient='vertical',legend_pos='left',图例方向和位置
    # is_legend_show=False,图例显示隐藏
    # label_formatter='{b}:{c}, {d}%',自定义显示系列名、数据名、数据值等
    pie.add("",attr,data,radius=[40,75],label_tet_color=None,is_label_show=True, label_formatter='{b}:{c}, {d}%',legend_orient='vertical',legend_pos='right')
    pie.render(r"C:\Programming\Python3\Test\商品种类(环形饼图).html")
    pie
    
    环形饼图Pie.png

    相关文章

      网友评论

          本文标题:颜值爆表的数据可视化库--Pyecharts

          本文链接:https://www.haomeiwen.com/subject/mpgqkqtx.html