w = wordcloud.WordCloud()
w.generate(txt) : 向WordCloud对象中加载文本txt
w.to_file(filename) : 将词云输出为图像文件, .png或.jpg格式
示例:
在终端中安装库:
代码:
import wordcloud w = wordcloud.WordCloud() txt = "python wordcloud example" w.generate(txt) filename = "test.png" w.to_file(filename)
代码结果:



