Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解


Posted in Python onFebruary 10, 2020

python可以在处理各种数据时,如果可以将这些数据,利用图表将其可视化,这样在分析处理起来,将更加直观、清晰,以下是 利用 PyEcharts 常用图表的可视化Demo, 开发环境 python3

柱状图

基本柱状图

from pyecharts import Bar
# 基本柱状图
bar = Bar("基本柱状图", "副标题")
bar.use_theme('dark') # 暗黑色主题
bar.add('真实成本',  # label
    ["1月", "2月", "3月", "4月", "5月", "6月"],  # 横坐标
    [5, 20, 36, 10, 75, 90],    # 纵坐标
    is_more_utils=True)  # 设置最右侧工具栏
# bar.show_config()    # 调试输出pyecharts的js的配置信息
bar.render('bar_demo.html') # 生成html文件

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

堆叠柱状图

# 堆叠柱状图
x_attr = ["1月", "2月", "3月", "4月", "5月", "6月"]
data1 = [5, 20, 36, 10, 75, 90]
data2 = [10, 25, 8, 60, 20, 80]
bar1 = Bar('柱状信息堆叠图')
bar1.add('商家1', x_attr, data1, is_stack=True)  # is_stack=True 表示堆叠在一起
bar1.add('商家2', x_attr, data2, is_stack=True)
bar1.render('bar1_demo.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

并列柱形图

# 并列柱形图
bar2 = Bar('并列柱形图', '标记线和标记示例')
bar2.add('商家1', x_attr, data1, mark_point=['average']) # 标记点:商家1的平均值
bar2.add('商家2', x_attr, data2, mark_line=['min', 'max']) # 标记线:商家2的最小/大值
bar2.render('bar2_demo.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

横向并列柱形图

# 横向并列柱形图

# 横向并列柱形图
bar3 = Bar('横向并列柱形图', 'X轴与Y轴交换')
bar3.add('商家1', x_attr, data1)
bar3.add('商家2', x_attr, data2, is_convert=True) # is_convert=True :X轴与Y轴交换
bar3.render('bar3_demo.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

以上相关柱状图完整代码bar_demo.py

from pyecharts import Bar
# 基本柱状图
bar = Bar("基本柱状图", "副标题")
bar.use_theme('dark') # 暗黑色主题
bar.add('真实成本',  # label
    ["1月", "2月", "3月", "4月", "5月", "6月"],  # 横坐标
    [5, 20, 36, 10, 75, 90],    # 纵坐标
    is_more_utils=True)  # 设置最右侧工具栏

# bar.show_config()    # 调试输出pyecharts的js的配置信息
bar.render('bar_demo.html') # 生成html文件


# 堆叠柱状图
x_attr = ["1月", "2月", "3月", "4月", "5月", "6月"]
data1 = [5, 20, 36, 10, 75, 90]
data2 = [10, 25, 8, 60, 20, 80]
bar1 = Bar('柱状信息堆叠图')
bar1.add('商家1', x_attr, data1, is_stack=True)  # is_stack=True 表示堆叠在一起
bar1.add('商家2', x_attr, data2, is_stack=True)
bar1.render('bar1_demo.html')


# 并列柱形图
bar2 = Bar('并列柱形图', '标记线和标记示例')
bar2.add('商家1', x_attr, data1, mark_point=['average']) # 标记点:商家1的平均值
bar2.add('商家2', x_attr, data2, mark_line=['min', 'max']) # 标记线:商家2的最小/大值
bar2.render('bar2_demo.html')

# 横向并列柱形图
bar3 = Bar('横向并列柱形图', 'X轴与Y轴交换')
bar3.add('商家1', x_attr, data1)
bar3.add('商家2', x_attr, data2, is_convert=True) # is_convert=True :X轴与Y轴交换
bar3.render('bar3_demo.html')

折线图、饼图、词云图

导入模块 与 基础数据

from pyecharts import Line
from pyecharts import Pie
from pyecharts import WordCloud
from pyecharts import EffectScatter, Overlap

x_attr = ["1月", "2月", "3月", "4月", "5月", "6月"]
data1 = [5, 20, 36, 10, 75, 90]
data2 = [10, 25, 8, 60, 20, 80]

基础折线示例图

# 折线示例图
line = Line("折线示例图")
line.add('商家1', x_attr, data1, mark_point=['average'])
line.add('商家2', x_attr, data2, is_smooth=True, mark_line=['max', 'average'])
line.render('line.demo.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

折线面积图

# 折线面积图
line = Line('折线面积示例图')
line.add('商家1', x_attr, data1, is_fill=True,line_opacity=0.2, area_opacity=0.4, symbol=None)
line.add('商家2', x_attr, data2, line_color='#000', area_opacity=0.3, is_smooth=True)
line.render('line2_demo.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

饼图

# 饼图
pie = Pie('饼图')
pie.add('', x_attr, data1, is_label_show=True)
pie.render('pie_demo.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

词云图

# 词云图
name = [
    'Though', 'the answer', 'this question',
    'may at first', 'seem to border', 'on the',
    'absurd', 'reflection', 'will show', 'that there',
    'is a', 'good deal', 'more in', 'it than meets', 'the eye'
    ]
value = [10000, 6189, 4556, 2356, 2233,
     1895, 1456, 1255, 981, 875,
     542, 462, 361, 265, 125]

worldcloud = WordCloud(width=1300, height=620)
worldcloud.add('词云', name, value, word_size_range=[20, 100])
worldcloud.render('worldcloud.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

线性闪烁图 —组合图

# 线性闪烁图
line2 = Line('线性闪烁图')
line2.add('line', x_attr, data1, is_random=True)

es = EffectScatter()
es.add('es', x_attr, data1, effect_scale=8) # 闪烁
overlop = Overlap()
overlop.add(line2)   # 必须先添加line 再添加 es
overlop.add(es)
overlop.render('line-es.html')

Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解

以上相关图完整代码line_pie_demo.py

from pyecharts import Line
from pyecharts import Pie
from pyecharts import WordCloud
from pyecharts import EffectScatter, Overlap

x_attr = ["1月", "2月", "3月", "4月", "5月", "6月"]
data1 = [5, 20, 36, 10, 75, 90]
data2 = [10, 25, 8, 60, 20, 80]

# 折线示例图
line = Line("折线示例图")
line.add('商家1', x_attr, data1, mark_point=['average'])
line.add('商家2', x_attr, data2, is_smooth=True, mark_line=['max', 'average'])
line.render('line.demo.html')

# 折线面积图
line = Line('折线面积示例图')
line.add('商家1', x_attr, data1, is_fill=True,line_opacity=0.2, area_opacity=0.4, symbol=None)
line.add('商家2', x_attr, data2, line_color='#000', area_opacity=0.3, is_smooth=True)
line.render('line2_demo.html')

# 饼图
pie = Pie('饼图')
pie.add('', x_attr, data1, is_label_show=True)
pie.render('pie_demo.html')

# 词云图
name = [
    'Python', 'the answer', 'this question',
    'may at first', 'seem to border', 'on the',
    'absurd', 'reflection', 'will show', 'that there',
    'is a', 'good deal', 'more in', 'it than meets', 'the eye'
    ]
value = [10000, 6189, 4556, 2356, 2233,
     1895, 1456, 1255, 981, 875,
     542, 462, 361, 265, 125]

worldcloud = WordCloud(width=1300, height=620)
worldcloud.add('词云', name, value, word_size_range=[20, 100])
worldcloud.render('worldcloud.html')

# 线性闪烁图
line2 = Line('线性闪烁图')
line2.add('line', x_attr, data1, is_random=True)

es = EffectScatter()
es.add('es', x_attr, data1, effect_scale=8) # 闪烁
overlop = Overlap()
overlop.add(line2)   # 必须先添加line 再添加 es
overlop.add(es)
overlop.render('line-es.html')

更多关于Python数据可视化处理库PyEcharts使用方法与实例请查看下面的相关链接

Python 相关文章推荐
python 文件和路径操作函数小结
Nov 23 Python
Tornado高并发处理方法实例代码
Jan 15 Python
python 重定向获取真实url的方法
May 11 Python
使用python的pandas库读取csv文件保存至mysql数据库
Aug 20 Python
python实现在函数图像上添加文字和标注的方法
Jul 08 Python
python requests使用socks5的例子
Jul 25 Python
Django实现web端tailf日志文件功能及实例详解
Jul 28 Python
python批量读取文件名并写入txt文件中
Sep 05 Python
Python Opencv提取图片中某种颜色组成的图形的方法
Sep 19 Python
python 字典有序并写入json文件过程解析
Sep 30 Python
Flask框架路由和视图用法实例分析
Nov 07 Python
Python values()与itervalues()的用法详解
Nov 27 Python
Python的pygame安装教程详解
Feb 10 #Python
windows下python安装pip方法详解
Feb 10 #Python
python3.6连接mysql数据库及增删改查操作详解
Feb 10 #Python
Django中modelform组件实例用法总结
Feb 10 #Python
python爬虫库scrapy简单使用实例详解
Feb 10 #Python
tensorflow 实现从checkpoint中获取graph信息
Feb 10 #Python
Python3 集合set入门基础
Feb 10 #Python
You might like
Session的工作方式
2006/10/09 PHP
PHP技术开发微信公众平台
2015/07/22 PHP
js loading加载效果实现代码
2009/11/24 Javascript
jquery实现的超出屏幕时把固定层变为定位层的代码
2010/02/23 Javascript
javascript获取xml节点的最大值(实现代码)
2013/12/11 Javascript
jquery live()重复绑定的解决方法介绍
2014/01/03 Javascript
js获取url中的参数且参数为中文时通过js解码
2014/03/19 Javascript
jQuery实现点击后标记当前菜单位置(背景高亮菜单)效果
2015/08/22 Javascript
js 动态生成html 触发事件传参字符转义的实例
2017/02/14 Javascript
js实现动态显示时间效果
2017/03/06 Javascript
详解vue模拟加载更多功能(数据追加)
2017/06/23 Javascript
在vue中使用Autoprefixed的方法
2018/07/27 Javascript
angular的输入和输出的使用方法
2018/09/22 Javascript
[05:34]2014DOTA2国际邀请赛中国区预选赛精彩TOPPLAY第二弹
2014/06/25 DOTA
[01:02:55]CHAOS vs Mineski 2019国际邀请赛小组赛 BO2 第二场 8.16
2019/08/18 DOTA
Python中的文件和目录操作实现代码
2011/03/13 Python
简单的python协同过滤程序实例代码
2018/01/31 Python
python脚本监控Tomcat服务器的方法
2018/07/06 Python
python生成九宫格图片
2018/11/19 Python
python树的同构学习笔记
2019/09/14 Python
用Python去除图像的黑色或白色背景实例
2019/12/12 Python
python 使用raw socket进行TCP SYN扫描实例
2020/05/05 Python
CSS3 倾斜的网页图片库实例教程
2009/11/14 HTML / CSS
乐高积木玩具美国官网:LEGO Shop US
2016/09/16 全球购物
什么是唯一索引
2015/07/05 面试题
介绍一下Mysql的存储引擎
2015/02/12 面试题
积极贯彻学习两会精神总结
2014/03/17 职场文书
创先争优承诺书范文
2014/03/31 职场文书
党员公开承诺书内容
2014/05/20 职场文书
暑期政治学习心得体会
2014/09/02 职场文书
党建工作整改措施
2014/10/28 职场文书
技能培训通讯稿
2015/07/18 职场文书
导游词之清晏园
2019/11/22 职场文书
Python使用Kubernetes API访问集群
2021/05/30 Python
Kubernetes中Deployment的升级与回滚
2022/04/01 Servers
victoriaMetrics库布隆过滤器初始化及使用详解
2022/04/05 Golang