标签:src image hit ima plot off plt show pyplot
from wordcloud import WordCloud
from scipy.misc import imread
import matplotlib.pyplot as plt
import jieba
def read_deal_text():
with open("ciyun.txt","r") as f:
txt=f.read()
re_move=[",","。"," ",‘\n‘,‘\xa0‘]
for i in re_move:
txt=txt.replace(i," ")
word=jieba.lcut(txt)
with open("txt_save.txt",‘w‘) as file:
for i in word:
file.write(str(i)+‘ ‘)
print("文本处理完成")
def img_grearte():
mask=imread("boy.png")
with open("txt_save.txt","r") as file:
txt=file.read()
word=WordCloud(background_color="white",\
width=800,\
height=800,
font_path=‘simhei.ttf‘,
mask=mask,
).generate(txt)
word.to_file(‘test.png‘)
print("词云图片已保存")
plt.imshow(word)
plt.axis("off")
plt.show()
read_deal_text()
img_grearte()
标签:src image hit ima plot off plt show pyplot
原文地址:https://www.cnblogs.com/gzz1/p/14716073.html