代码实现
import jieba
import wordcloudf = open("D:/Pythonstudy/data/平凡的世界.txt", "r", encoding="utf-8")
t = f.read()
print(t)
f.close()
ls = jieba.lcut(t)
txt = " ".join(ls)w = wordcloud.WordCloud(font_path="D:/ccc/Fonts.TTF", width = 1000, height = 700, background_color = "white",mode="RGBA")
w.generate(txt)
w.to_file("pfdsj.png")
遇见问题
中文字体生成词云图片时会生成矩形框,解决办法:引入本地的字体