溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用Python快速制作可視化報表的方法

發(fā)布時間:2020-10-03 14:43:34 來源:腳本之家 閱讀:403 作者:面膜08 欄目:開發(fā)技術

我們可以試用可視化包——Pyechart。

Echarts是百度開源的一個數(shù)據(jù)可視化JS庫,主要用于數(shù)據(jù)可視化。

pyecharts是一個用于生成Echarts圖標的類庫。實際就是Echarts與Python的對接。

安裝

pyecharts兼容Python2和Python3。執(zhí)行代碼:

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("各商家產(chǎn)品銷售情況")
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("各產(chǎn)品銷售情況")
pie.add("",attr,v1,is_label_show=True)
pie  #pie.render()

使用Python快速制作可視化報表的方法

3.圓環(huán)圖

from pyecharts import Pie
attr=["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","鞋子"]
v1=[11,12,13,10,10,10]
pie=Pie("餅圖—圓環(huán)圖示例",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("業(yè)務指標完成率—儀表盤")
gauge.add("業(yè)務指標","完成率",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快速制作可視化報表的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI