import wordcloud
import numpy
as np
import matplotlib
.pyplot
as plt
import PIL
import jieba
import re
with open(r
'D:\python3.7\ZG_jiaoyu\coding\stage_2_coding\you_get1\text2.txt',encoding
='gbk') as f
:
text2
= f
.readlines
()
image1
= PIL
.Image
.open(r
'D:\python3.7\ZG_jiaoyu\coding\stage_2_coding\you_get1\h.jpg')
MASK
= np
.array
(image1
)
WC
= wordcloud
.WordCloud
(font_path
= 'C:\\Windows\\Fonts\\simhei.ttf',max_words
=2000,mask
= MASK
,height
= 400,width
=400,background_color
='red',repeat
=False,mode
='RGBA')
st1
= re
.sub
('[,。、“”‘ ’]','',str(text2
))
conten
= ' '.join
(jieba
.lcut
(st1
))
con
= WC
.generate
(conten
)
plt
.imshow
(con
)
plt
.axis
("off")
plt
.savefig
('fu')
plt
.show
()
plt
.show
()
摘抄自:https://blog.csdn.net/moshanghuali/article/details/84667136
转载请注明原文地址: https://lol.8miu.com/read-38927.html