Skip to content

Commit c26ed04

Browse files
author
xuming06
committed
add wordcloud and update gensim demo.xuming 20170731
1 parent 271b9cb commit c26ed04

27 files changed

Lines changed: 32452 additions & 119 deletions
File renamed without changes.

12gensim/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
@author: XuMing <[email protected]>
5+
@summary:
6+
"""
7+

13wordcloud/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
@author: XuMing <[email protected]>
5+
@summary:
6+
"""
7+

13wordcloud/chinese-wordcloud.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
@author: XuMing <[email protected]>
5+
@summary:
6+
"""
7+
import matplotlib.pyplot as plt
8+
import pickle
9+
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
10+
import jieba
11+
12+
text = open('../data/tianlongbabu.txt', encoding='utf8').read()
13+
text = ' '.join(jieba.lcut(text))
14+
with open('../data/stopword.txt', encoding='utf-8') as f:
15+
for line in f:
16+
STOPWORDS.add(line.strip())
17+
print("stopwrod size:" + len(STOPWORDS))
18+
backgroud_Image = plt.imread('../data/cloud/girl.jpg')
19+
wc = WordCloud(background_color='white', # 设置背景颜色
20+
# mask=backgroud_Image, # 设置背景图片
21+
# max_words=2000, # 设置最大现实的字数
22+
stopwords=STOPWORDS, # 设置停用词
23+
font_path='/System/Library/Fonts/STHeiti Light.ttc',
24+
# font_path = 'C:/Users/Windows/fonts/msyh.ttf',# 设置字体格式,如不设置显示不了中文
25+
)
26+
wc.generate(text)
27+
plt.imshow(wc)
28+
plt.axis('off')
29+
plt.show()

0 commit comments

Comments
 (0)