python 绘制百度实时统计柱状图


import csv
import matplotlib.pyplot as plt
import jieba.analyse

def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x()+rect.get_width()/2, height, height, ha='center', va='bottom')

filename = 'm.csv'
seacherWord=""
num=20
# 打开文件
with open(filename,'r',encoding='UTF-8') as f:
    reader = csv.reader(f)
    # 读取表头数据。
    header_row = next(reader)
    for row in reader:
        seacherWord=seacherWord+row[5]
#结巴分词
tags = jieba.analyse.extract_tags(seacherWord, topK=num, withWeight=False)

with open(filename,'r',encoding='UTF-8') as f:
    reader = csv.reader(f)
    # 读取表头数据。
    header_row = next(reader)
    visitTime=list(range(num))
    visitNum=list(range(num))
    for row in reader:
        for i in range(len(tags)):
            if tags[i] in row[5]:
                if (row[10] !="未知") and (row[10] !="正在访问s") and (row[10] !=" "):
                    visitNum[i] += 1
                    visitTime[i] += int(row[10].rstrip('s'))
print(tags)
print(visitNum)
print(visitTime)
plt.rc('font', family='SimHei', size=8)#设置中文显示,否则出现乱码!
a=plt.bar(range(len(visitTime)), visitTime, color='rgby', tick_label=tags)
autolabel(a)
plt.title('PC搜索最多关键字的浏览时间/秒')
plt.legend()
plt.show()

 

转载于:https://my.oschina.net/u/3474729/blog/3078895

你可能感兴趣的:(python 绘制百度实时统计柱状图)