简易版词云代码
from wordcloud import WordCloud
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 读取文本内容
text = "Python is a high-level programming language with powerful standard library and easy to learn."
# 生成词云
wordcloud = WordCloud().generate(text)
# 显示词云
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
通过检索可知,是由于Pillow的版本未更新导致的
直接在终端或者anaconda的终端运行,需要Pillow的版本大于4.0.0以上才可以
pip install --upgrade Pillow
更新成功即可运行,如下图所示: