mirror of
https://github.com/WMK965/965-Python-Learning-Repo.git
synced 2025-04-28 02:23:21 +00:00
添加练习内容(词云)
This commit is contained in:
parent
9f9301876c
commit
19e2a4ace4
18
Wordcloud.py
Normal file
18
Wordcloud.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import jieba
|
||||||
|
import wordcloud
|
||||||
|
from PIL import Image
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
raw_data = open("./resources/111.txt", encoding="gbk").read()
|
||||||
|
ls = jieba.lcut(raw_data)
|
||||||
|
text = ' '.join(ls)
|
||||||
|
open("./resources/111.txt", encoding="gbk").close()
|
||||||
|
mask = np.array(Image.open("./resources/mask.png"))
|
||||||
|
wc = wordcloud.WordCloud(font_path="msyh.ttc",
|
||||||
|
mask=mask,
|
||||||
|
background_color='white',
|
||||||
|
max_font_size=240,
|
||||||
|
stopwords={'王勃', '一'})
|
||||||
|
wc.generate(text)
|
||||||
|
wc.to_file("./results/111.png")
|
17
temp.py
17
temp.py
@ -1,18 +1 @@
|
|||||||
import jieba
|
|
||||||
import wordcloud
|
|
||||||
from PIL import Image
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
|
||||||
raw_data = open("./resources/111.txt", encoding="gbk").read()
|
|
||||||
ls = jieba.lcut(raw_data)
|
|
||||||
text = ' '.join(ls)
|
|
||||||
open("./resources/111.txt", encoding="gbk").close()
|
|
||||||
mask = np.array(Image.open("./resources/mask.png"))
|
|
||||||
wc = wordcloud.WordCloud(font_path="msyh.ttc",
|
|
||||||
mask=mask,
|
|
||||||
background_color='white',
|
|
||||||
max_font_size=240,
|
|
||||||
stopwords={'王勃', '一'})
|
|
||||||
wc.generate(text)
|
|
||||||
wc.to_file("./results/111.png")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user