序言
哈佛大学的校训之一:你所浪费的今天,是逝去的人所奢望的明天;你所厌恶的现在,是未来的你回不去的曾经。
数据
展示
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')