## 数据准备 worddict = {} ## 构造{词语:频率}字典 for key,value in zip(word_stat.Word,word_stat.number): worddict[key] = value ## 生成词云 ## 查看其中的10个元素 for ii,myword in zip(range(10),worddict.items()): print(ii) print(myword) redcold = WordCloud(font_path=r"C:/Windows/Fonts/STFANGSO.TTF", margin=5, width=1800, height=1800) worddict=worddict.items()#文本词频 worddict=dict(worddict) #redcold.generate(worddict) #文本 redcold.generate_from_frequencies(frequencies=worddict) #词频 plt.figure(figsize=(10,10)) plt.imshow(redcold) plt.axis("off") plt.show()
时间: 2024-03-30 11:37:58 浏览: 45
这是一段Python代码,用于生成词云。首先,它构造了一个字典worddict,其中key是词语,value是词频。然后,它使用WordCloud库生成一个词云,设置了字体路径、边距、宽度和高度等参数。接着,它将worddict转换为一个元组列表,并将其转换为字典,然后使用generate_from_frequencies方法生成词云。最后,使用matplotlib库展示词云图。
阅读全文
相关推荐

















