mirror of
https://github.com/WMK965/965-Python-Learning-Repo.git
synced 2025-04-27 20:13:21 +00:00
添加练习内容(词云)
This commit is contained in:
parent
d3f268475e
commit
c053919887
0
ex3.csv → resources/ex3.csv
Executable file → Normal file
0
ex3.csv → resources/ex3.csv
Executable file → Normal file
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 297 KiB After Width: | Height: | Size: 297 KiB |
4
temp.py
4
temp.py
@ -8,11 +8,11 @@ raw_data = open("111.txt", encoding="gbk").read()
|
|||||||
ls = jieba.lcut(raw_data)
|
ls = jieba.lcut(raw_data)
|
||||||
text = ' '.join(ls)
|
text = ' '.join(ls)
|
||||||
open("111.txt", encoding="gbk").close()
|
open("111.txt", encoding="gbk").close()
|
||||||
mask = np.array(Image.open("mask.png"))
|
mask = np.array(Image.open("./resources/mask.png"))
|
||||||
wc = wordcloud.WordCloud(font_path="msyh.ttc",
|
wc = wordcloud.WordCloud(font_path="msyh.ttc",
|
||||||
mask=mask,
|
mask=mask,
|
||||||
background_color='white',
|
background_color='white',
|
||||||
max_font_size=240,
|
max_font_size=240,
|
||||||
stopwords={'王勃', '一'})
|
stopwords={'王勃', '一'})
|
||||||
wc.generate(text)
|
wc.generate(text)
|
||||||
wc.to_file("111.png")
|
wc.to_file("./results/111.png")
|
||||||
|
Loading…
Reference in New Issue
Block a user