添加练习内容(词云)

This commit is contained in:
965 2023-05-23 22:12:50 +08:00
parent d3f268475e
commit c053919887
5 changed files with 2 additions and 2 deletions

0
ex3.csv → resources/ex3.csv Executable file → Normal file
View File

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 297 KiB

View File

@ -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")