import import import
pandas as pd
os,jieba,re,random,wordcloud
matplotlib.pyplot as plt
from PIL import Image
wzdir = "./2021 浙江高考满分作文/"
wz = os.listdir(wzdir) #获得文件夹中所有文件的名称列表
wzrd = ①
f=open(wzdir+wzrd[0],encoding="utf-8")
dd=f.read ()
f.close()
#使用正则表达式去除文章中的标点符号
ss = re.sub("[、,。:“”;? ]","",dd)
wb = jieba.lcut(ss,cut_all=True)
word = {}
for i in wb:
t =i.strip()
if len(t)>1:
if t in word:
word[t]+=1
else:
②
wc = wordcloud.WordCloud(font_path="msyh.ttc", width=800, height=600) wc.background_color="white"
wc.fit_words (word)
img = wc.to_array()
plt.rcParams['font.sans-serif']=['SimHei'] plt.figure()
plt.imshow(img)
plt.axis(False)
plt.title(wzrd[0].split(".")[0])
③
#支持中文显示