数据
展示
from wordcloud import WordCloud
import jieba
import numpy
import PIL.Image as Image
def cut(text):
wordlist_jieba = jieba.cut(text)
space_wordlist = " ".join(wordlist_jieba)
return space_wordlist
with open("我不是药神.txt", encoding="utf-8")as file:
text = file.read()
# 分词
text = cut(text)
mask_pic = numpy.array(Image.open("地图.png"))
wordcloud = WordCloud(font_path="STHeiti-Light.ttc",
collocations=False,
background_color="white",
max_words=1000,
#stopwords=["的", "电影", "也", "了", "是", "都"],
mask=mask_pic
).generate(text)
image = wordcloud.to_image()
wordcloud.to_file('词云_03.png')
如果学习上有遇到问题,加/:yiyi990805(备注:阿里云tony)即可。