我曾经nltk.tokenize标记一个 txt 文件,它生成了一个新文件,我们称之为“File_B”。
然后我运行:
from wordcloud import WordCloud
import matplotlib.pyplot as plt
text = open('File_B').read()
wordcloud = WordCloud(width=1600, height=800).generate(text)
wordcloud = WordCloud(font_path=font_path, width=1600, height=800).generate(text)
plt.figure(figsize=(20,10))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.tight_layout(pad=0)
plt.savefig("wordcloud.png", bbox_inches='tight')
这是结果:
https://i.stack.imgur.com/RnoJ7.png
每个单词的末尾都有一个撇号,即使它们不在 File_B 中。我错过了什么?