使用Python快速制作可视化报表的方法

yipeiwu_com5年前Python基础

我们可以试用可视化包——Pyechart。

Echarts是百度开源的一个数据可视化JS库,主要用于数据可视化。

pyecharts是一个用于生成Echarts图标的类库。实际就是Echarts与Python的对接。

安装

pyecharts兼容Python2和Python3。执行代码:

pip install pyecharts(快捷键Windows+R——输入cmd)

初级图表

1.柱状图/条形图

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#bar.render()

Python 可视化报表

2.饼图

from pyecharts import Pie
attr=["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","鞋子"]
v1=[11,12,13,10,10,10]
pie=Pie("各产品销售情况")
pie.add("",attr,v1,is_label_show=True)
pie  #pie.render()

Python 可视化报表

3.圆环图

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

Python 可视化报表

4.散点图

from pyecharts import Scatter
v1=[10,20,30,40,50,60]
v2=[10,20,30,40,50,60]
scatter=Scatter("散点图示例")
scatter.add("A",v1,v2)
scatter.add("B",v1[::-1],v2)
scatter

Python 可视化报表

5.仪表盘

from pyecharts import Gauge
gauge=Gauge("业务指标完成率—仪表盘")
gauge.add("业务指标","完成率",66.66)
gauge

Python 可视化报表

6.热力图

import random
from pyecharts import HeatMap
x_axis=[
 "12a","1a","2a","3a","4a","5a","6a","7a","8a","9a","10a","11a",
 "12p","1p","2p","3p","4p","5p","6p","7p","8p","9p","10p","11p",]
y_axis=[
 "Saturday","Friday","Thursday","Wednesday","Tuesday","Monday","Sunday"]
data=[[i,j,random.randint(0,50)] for i in range(24) for j in range(7)]
heatmap=HeatMap()
heatmap.add("热力图直角坐标系",x_axis,y_axis,data,is_visualmap=True,
   visual_text_color="#000",visual_orient="horizontal")
heatmap

Python 可视化报表

高级图表

1.漏斗图

from pyecharts import Funnel
attr=["潜在","接触","意向","明确","投入","谈判","成交"]
value=[140,120,100,80,60,40,20]
funnel=Funnel("销售管理分析漏斗图")
funnel.add("商品",attr,value,is_label_show=True,
   label_pos="inside",label_text_color="#fff")
funnel

2.词云图

Python 可视化报表

from pyecharts import WordCloud
name=[
 "Sam s Club","Macys","Amy Schumer","Jurassic World","Charter Communications",
 "Chick Fil A","Planet Fitness","Pitch Perfect","Express","Home","Johnny Depp",
 "Lena Dunham","Lewis Hamilton","KXAN","Mary Ellen Mark","Farrah Abraham",
 "Rita Ora","Serena Williams","NCAA baseball tournament","Point Break"
]
value=[
 10000,6181,4386,4055,2467,2244,1898,1484,1112,
 965,847,582,555,550,462,366,360,282,273,265]
wordcloud=WordCloud(width=1300,height=620)
wordcloud.add("",name,value,word_size_range=[20,100])
wordcloud

Python 可视化报表

3.组合图

from pyecharts import Line,Pie,Grid
line=Line("折线图",width=1200)
attr=["周一","周二","周三","周四","周五","周六","周日"]
line.add("最高气温",attr,[11,11,15,13,12,13,10],
  mark_point=["max","min"],mark_line=["average"])
line.add("最低气温",attr,[1,-2,2,5,3,2,0],
  mark_point=["max","min"],mark_line=["average"],
  legend_pos="20%")
attr=["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
v1=[11,12,13,10,10,10]
pie=Pie("饼图",title_pos="55%")
pie.add("",attr,v1,radius=[45,65],center=[65,50],
  legend_pos="80%",legend_orient="vertical")
grid=Grid()
grid.add(line,grid_right="55%")
grid.add(pie,grid_left="60%")
grid

Python 可视化报表

以上这篇使用Python快速制作可视化报表的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Linux中安装Python的交互式解释器IPython的教程

IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性。特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键...

详解django中自定义标签和过滤器

详解django中自定义标签和过滤器

想要实现自定义标签和过滤器需要进行准备工作: 准备(必需)工作: 1  在某个app下创建一个名为templatetags(必需,且包名不可变)的包。假设我们在名为polls的...

Python中实现变量赋值传递时的引用和拷贝方法

iamlaosong文 曾经看到这样一个问题,一个字典中的元素是列表,将这个列表元素赋值给一个变量,然后修改这个列表中元素的值,结果发现,字典中那个列表也同样修改了。 那个问题如下:...

Python中的包和模块实例

一、实例和结果 1)实例的结构和具体的文件: 复制代码 代码如下: PyPackage │  PyCommonM.py │  __init__.py │ ├─p1Pa...

简介Django框架中可使用的各类缓存

数据库缓存 为了使用数据库表作为缓存后端,首先在数据库中运行这个命令以创建缓存表: python manage.py createcachetable [cache_table_na...