码迷,mamicode.com
首页 > 其他好文 > 详细

ciyunzuoye

时间:2021-04-29 12:18:48      阅读:0      评论:0      收藏:0      [点我收藏+]

标签: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()

技术图片

ciyunzuoye

标签:src   image   hit   ima   plot   off   plt   show   pyplot   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!