因为需要一个html形式的数据统计界面,所以做了一个基于pyecharts包的可视化程序,当然matplotlib还是常用的数据可视化包,只不过各有优劣;基本功能概述就是读取csv文件数据,对每列进行数据统计并可视化,最后形成html动态界面,选择pyecharts的最主要原因就是这个动态界面简直非常炫酷。
先上成品图:
数据读取和数据分析模块:
#导入csv模块 import csv #导入可视化模块 from matplotlib import pyplot as plt from pylab import mpl import numpy as np import random from pyecharts import Line,Pie,Grid,Bar,WordCloud #指定文件名,然后使用 with open() as 打开 python_file = 'haiyang.csv' #filename = 'release/111.csv' #python3 LieCharts.py test_chart --python_file 'haiyang.csv' with open(python_file) as f: #创建一个阅读器:将f传给csv.reader reader = csv.reader(f) #使用csv的next函数,将reader传给next,将返回文件的下一行 header_row = next(reader) for index, column_header in enumerate(header_row): print(index, column_header) #读取置信度 #创建置信度的列表 confidences =[] #创建风险等级数组 highRisk = [] middleRisk = [] lowRisk = [] noRisk = [] person = [] #创建时间点 timePoint = [] #文件信息 fileInformation = [] #遍历reader的余下的所有行(next读取了第一行,reader每次读取后将返回下一行) for row in reader: # 下面就是对某一列数据进行遍历,因为项目保密,就不列出具体代码了,其实就是各种循环语句,大家根据自己的数据简单写一下就行 fileInformation.append('某某某某') fileInformation.append(row[0]) fileInformation.append(row[1]) fileInformation.append(row[2]) fileInformation.append(len(confidences)) int_confidences = [] for i in confidences: # 同上 len_noRisk = len(noRisk) len_lowRisk = len(lowRisk) len_middleRisk = len(middleRisk) len_highRisk = len(highRisk) len_person = len(person) total = int(len_person+len_highRisk+len_middleRisk+len_lowRisk+len_noRisk) if (len_highRisk > total/2): # 同上
数据可视化模块:
pie_title = Pie('某某某分析报表', "", title_pos='center',title_top="1%",title_text_size=42,subtitle_text_size=20) value=[10000,6181,4386,4055,4000] wordcloud=WordCloud(width=30,height=12,title="某某某某信息",title_pos="22%",title_top="12%",title_text_size=32) wordcloud1=WordCloud(width=30,height=12,title="某某:"+fileInformation[1],title_pos="22%",title_top="22%",title_text_size=26) wordcloud2=WordCloud(width=30,height=12,title="某某:"+fileInformation[2],title_pos="22%",title_top="30%",title_text_size=26) #wordcloud3=WordCloud(width=30,height=12,title="音频采样率:"+fileInformation[3],title_pos="22%",title_top="38%",title_text_size=26) #wordcloud4=WordCloud(width=30,height=12,title="总时长/s:"+fileInformation[4],title_pos="22%",title_top="36%",title_text_size=32) # wordcloud.add("",fileInformation,value,word_size_range=[20,100],rotate_step=3 # ,xaxis_pos=200,grid_left="1%",grid_bottom="50%",grid_top="5%",grid_right="80%") #折线图 line=Line("某某某某某走势图",title_pos='center',title_top="51%",title_text_size=32,width=600,height = 20) attr=timePoint line.add("某某某某某",attr,int_confidences,legend_pos="85%",legend_top="54%", mark_point=["max","min"],mark_line=["average"]) #饼图 attr=["某某某某", "某某某某", "某某某某", "某某某"] v1=[len_highRisk, len_middleRisk, len_lowRisk,len_noRisk] pie=Pie("某某某某某某某",title_pos="65%",title_top="12%",title_text_size=32,width=100,height = 100) pie.add("",attr,v1,radius=[0,30],center=[71,35], legend_pos="85%",legend_top="20%" ,legend_orient="vertical") grid=Grid(width = 1800 ,height= 900)#调整画布大小 grid.add(line,grid_left="5%",grid_bottom="2%",grid_top="60%") grid.add(pie_title,grid_bottom="10%") grid.add(wordcloud,grid_left="1%",grid_bottom="50%",grid_top="5%",grid_right="80%") grid.add(wordcloud1,grid_left="1%",grid_bottom="50%",grid_top="5%",grid_right="80%") grid.add(wordcloud2,grid_left="1%",grid_bottom="50%",grid_top="5%",grid_right="80%") #grid.add(wordcloud3,grid_left="1%",grid_bottom="50%",grid_top="5%",grid_right="80%") #grid.add(wordcloud4,grid_left="1%",grid_bottom="50%",grid_top="5%",grid_right="80%") grid.add(pie,grid_left="50%",grid_bottom="50%") #grid.render() grid.render(path='./release/XXXX.html')
根据需求这个还可以跨平台跨语言调用,比如C++程序调用python进行数据分析。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO
- 钟镇涛-《百分百钟镇涛》首批限量版SACD-ISO
- 群星《继续微笑致敬许冠杰》[低速原抓WAV+CUE]
- 潘秀琼.2003-国语难忘金曲珍藏集【皇星全音】【WAV+CUE】
- 林东松.1997-2039玫瑰事件【宝丽金】【WAV+CUE】