小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

wordcloud詞云分析及詞頻統(tǒng)計繪圖

 小飛苑 2017-11-15
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-10-18 17:52:25 # @Author : awakeljw (liujw15@mails.tsinghua.edu.cn) # @Link : http://blog.csdn.net/awakeljw/ # @Version : $Id$ from wordcloud import WordCloud import jieba import PIL import matplotlib.pyplot as plt import numpy as np from collections import Counter import matplotlib from pylab import mpl mpl.rcParams['font.sans-serif'] = ['SentyTang'] # 指定默認(rèn)字體 mpl.rcParams['axes.unicode_minus'] = False matplotlib.rc('xtick', labelsize=14) matplotlib.rc('ytick', labelsize=14) def wordcloudplot(txt): path='字體文件' # path=unicode(path, 'utf8').encode('gb18030') alice_mask = np.array(PIL.Image.open('圖片文件')) wordcloud = WordCloud(font_path=path, background_color="white", margin=5, width=1800, height=800,mask=alice_mask,max_words=2000,max_font_size=60,random_state=42) wordcloud = wordcloud.generate(txt) wordcloud.to_file('輸出文件') plt.imshow(wordcloud) plt.axis("off") plt.show() rem = [',','、','。','的','和','\u3000','圖','串','“','”',' ','與','是','端','在','中','了','\n'] def main(): a=[] f=open(r'I:\tensorflow\ciyun\paper.txt','r',encoding='gb18030').read() words=list(jieba.cut(f)) tongji = Counter(words).most_common(20) d = {key: value for (key, value) in tongji} for i in list(d.keys()): if i in rem: d.pop(i) print (d) label = list(d.keys()) y = list(d.values()) idx = np.arange(len(y)) plt.barh(idx,y) plt.yticks(idx+0.4,label) plt.xlabel('出現(xiàn)次數(shù)',fontsize = 20,labelpad = 5) plt.ylabel('關(guān)鍵詞',fontsize= 20,labelpad = 5) plt.title('渦流發(fā)生器對激波串振蕩的控制',fontsize= 25) plt.savefig('輸出詞頻圖標(biāo)') #plt.show() #繪制pie chart on polar axis N = len(d) theta = np.arange(0.0, 2*np.pi,2*np.pi/N) radii = y width = np.pi/6 ax = plt.subplot(111,projection='polar') bars = ax.bar(theta, radii, width = width, bottom = 0.0) plt.xticks(theta+np.pi/12,label) for r, bar in zip(radii, bars): bar.set_facecolor(plt.cm.viridis(r / 10.)) bar.set_alpha(0.5) plt.savefig('輸出pie極坐標(biāo)圖') plt.show() for word in words: if len(word)>1: a.append(word) txt=r' '.join(a) wordcloudplot(txt)#輸出詞云 if __name__=='__main__': main()

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約