专栏首页python3使用Python快速制作可视化报表

使用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()

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()

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

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

5.仪表盘

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

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

高级图表

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.词云图

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

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 万能的python-画图

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

    py3study
  • Python带参装饰器

      原函数对象的属性都被替换了,而使用装饰器,我们的需求是查看被封装函数的属性,如何解决?

    py3study
  • 数据分析——pyecharts

    py3study
  • 万能的python-画图

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

    py3study
  • Vue框架Element UI教程-时间选择器(二)

    Element UI手册:https://cloud.tencent.com/developer/doc/1270 中文文档:http://element-c...

    祈澈菇凉
  • 实战|流式代码封装及ViewBadger角标的应用(附源码)

    本来这章只是想讲一个Android中的角标ViewBadger的使用,在写的过程中想起来前面文章中Glide的开源库加载网络图片用一行代码就可以直接实现了,这种...

    Vaccae
  • 如何将Redux与React Hooks一起使用

    React Redux在2019年6月11日发布的7.1版中提供了对Hooks的支持。这意味着我们可以在函数组件中将Redux与Hooks一起使用,而不是使用高...

    前端知否
  • react-native 开发笔记 (二)

    app的导航路径是tab->tabItem->tabItemChild,交互设计的要求是tab子页面的显示是要盖过tab导航条的,如果我们把tab作为根组件,N...

    frontoldman
  • IC重大项目落户南京浦口高新区,AI芯片“双目视觉”成亮点

    同时,南京集成电路产业联盟正式成立,为支持集成电路产业垂直整合及并购重组,建立总规模200亿美元的南京市集成电路产业投资基金。

    镁客网
  • 20180826_ARTS_week09

    第一种方法,把数字转成字符串,再变成数组,倒转,然后再变回字符串。 很明显,这个方法效率不高。

    Bob.Chen

扫码关注云+社区

领取腾讯云代金券