Skip to content

Commit 8837e2d

Browse files
committed
m
1 parent 10eb56b commit 8837e2d

File tree

7 files changed

+1565
-0
lines changed

7 files changed

+1565
-0
lines changed

yeke/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
+ [py-scratch](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-scratch) :不到 50 行 Python 代码,做个刮刮卡
1414
+ [py-xxl](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-xxl) :用 Python 写个消消乐小游戏
1515
+ [py-sun](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-sun) :用 Python 动态模拟太阳系的运转
16+
+ [py-aljx](https://github.com/JustDoPython/python-examples/tree/master/yeke/py-aljx) :阿里注册了新公司京西,用 Python 看看网友怎么说
1617

1718
---
1819

yeke/py-aljx/__init__.py

Whitespace-only changes.

yeke/py-aljx/aljx_cloud.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from wordcloud import WordCloud
2+
import numpy as np, jieba
3+
from PIL import Image
4+
5+
def jieba_():
6+
stop_words = []
7+
with open('stop_words.txt', 'r', encoding='utf-8') as f:
8+
lines = f.readlines()
9+
for line in lines:
10+
stop_words.append(line.strip())
11+
content = open('aljx.txt', 'rb').read()
12+
# jieba 分词
13+
word_list = jieba.cut(content)
14+
words = []
15+
for word in word_list:
16+
if word not in stop_words:
17+
words.append(word)
18+
global word_cloud
19+
# 用逗号隔开词语
20+
word_cloud = ','.join(words)
21+
22+
def cloud():
23+
# 打开词云背景图
24+
cloud_mask = np.array(Image.open('bg.png'))
25+
# 定义词云的一些属性
26+
wc = WordCloud(
27+
# 背景图分割颜色为白色
28+
background_color='white',
29+
# 背景图样
30+
mask=cloud_mask,
31+
# 显示最大词数
32+
max_words=300,
33+
# 显示中文
34+
font_path='./fonts/simhei.ttf',
35+
# 最大尺寸
36+
max_font_size=100
37+
)
38+
global word_cloud
39+
# 词云函数
40+
x = wc.generate(word_cloud)
41+
# 生成词云图片
42+
image = x.to_image()
43+
# 展示词云图片
44+
image.show()
45+
# 保存词云图片
46+
wc.to_file('cloud.png')
47+
48+
jieba_()
49+
cloud()

yeke/py-aljx/bg.PNG

47.5 KB
Loading

yeke/py-aljx/cloud.png

154 KB
Loading

0 commit comments

Comments
 (0)