from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
txt = open("docu/三国演义.txt", "r", encoding='utf-8').read()
wlist = jieba.cut(txt,cut_all = True)
mylist = "".join(wlist)
stopword = {"将军","却说","荆州","二人","不可","不能","如此"}
font = "file:///C:/WINDOWS/Fonts/STZHONGS.TTF"
wc = WordCloud(
background_color='white',
width=2000,
height=1200,
font_path=font,
stopwords=stopword,
max_words = 100)
wc.generate_from_text(mylist)
plt.imshow(wc)
plt.axis('off')
plt.show()
font_path = "C:/Windows/Fonts/simfang.ttf",写做错了你下面调用的是
font_path = fpnt_path
改一下
wordcloud = WorldCloud()
这个你重复定义了,你下面已经定义了一个wd,建以吧wordcloud=WorldCloud()删掉
第6行打错单词了,是WordCloud