Python模块--PyEcharts

一、PyEcharts简介

  “pyecharts 是一个用于生成 Echarts 图表的类库。Echarts 是百度开源的一个数据可视化 JS 库。用 Echarts 生成的图可视化效果非常棒,为了与 Python 进行对接,方便在 Python 中直接使用数据生成图”。
  pyecharts可以展示动态图,在线报告使用比较美观,并且展示数据方便,鼠标悬停在图上,即可显示数值、标签等。
官网地址:http://pyecharts.org/#/zh-cn/charts

https://pyecharts.org/#/zh-cn/quickstart
https://github.com/pyecharts/pyecharts

二、模块安装

下载安装:(推荐)
https://pypi.org/project/pyecharts/0.1.9.4/#files

pip install pyecharts-0.1.9.4-py2.py3-none-any.whl 

 

 在线安装,不成功:

(film) C:\Users\Administrator>pip install pyecharts

 

三、图表示例

  1. 柱形图
 1 # -*- coding: utf-8 -*-
 2 
 3 from pyecharts import Bar
 4 
 5 '''
 6 柱形图
 7 '''
 8 
 9 bar = Bar("我的第一个图表", "这里是副标题")
10 bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
11 bar.show_config()
12 bar.render()

会生成Html文件(render.html):

 

2.  柱状图数据堆叠

# -*- coding: utf-8 -*-

from pyecharts import Bar

'''
柱状图数据堆叠
'''

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图数据堆叠示例")
bar.add("商家A", attr, v1, is_stack=True)
bar.add("商家B", attr, v2, is_stack=True)
bar.show_config()
bar.render()

 

3. 散点图

# -*- coding: utf-8 -*-

from pyecharts import EffectScatter
'''
散点图
'''

v1 = [10, 20, 30, 40, 50, 60]
v2 = [25, 20, 15, 10, 60, 33]
es = EffectScatter("带有涟漪特效动画的动态散点图示例")
es.add("effectScatter", v1, v2)
es.render()

 

 4. 漏斗图

# -*- coding: utf-8 -*-

from pyecharts import Funnel
'''
漏斗图
'''

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
value = [20, 40, 60, 80, 100, 120]
funnel = Funnel("漏斗图示例")
funnel.add("商品", attr, value, is_label_show=True, label_pos="inside", label_text_color="#fff")
funnel.render()

 

 5. 饼图

# -*- coding: utf-8 -*-

from pyecharts import Pie
'''
饼图
'''

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图示例")
pie.add("", attr, v1, is_label_show=True)
pie.render()

 

 6. 圆环图

# -*- coding: utf-8 -*-

from pyecharts import Pie
'''
圆环图
'''

attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图-圆环图示例", title_pos='center')
pie.add("", attr, v1, radius=[40, 75], label_text_color=None,
        is_label_show=True, legend_orient='vertical',
        legend_pos='left')
pie.render()

 

 7. 仪表盘

# -*- coding: utf-8 -*-

from pyecharts import Gauge

'''
仪表盘
'''

gauge = Gauge("仪表盘示例")
gauge.add("业务指标", "完成率", 66.66)
gauge.show_config()
gauge.render()

 

 

 




posted @ 2020-08-20 00:06  璐璐呦  阅读(613)  评论(0)    收藏  举报