Wordcloud设置参数font_path = “” Mac 系统中使用:
font_path="Hiragino Sans GB.ttc"
代码效果:
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
path_txt = 'word.txt' # 随便一个新闻
file = open(path_txt,'r',encoding='UTF-8').read()
cut_text = " ".join(jieba.cut(file))
wordcloud = WordCloud(
font_path="Hiragino Sans GB.ttc",
# 背景,宽高
background_color="white",
width=1000,
height=880).generate(cut_text)plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()