首页 > 其他 > 详细

ciyunzuoye

时间:2021-04-29 10:13:11      阅读:28      评论:0      收藏:0      [点我收藏+]

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()

技术分享图片

ciyunzuoye

原文:https://www.cnblogs.com/gzz1/p/14716073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!