使用wordcloud模块,生成云图,测试文本为:
Betty Botter bought some butter but she said the butter’s bitter. If I put it in my batter it will make my batter bitter. So, she bought some better butter, better than the bitter butter and she put it in her batter and her
需要使用python的第三方类库jieba、matplotlib、wordcloud,如果没有请用pip安装。
代码实现
import jieba
import matplotlib.pyplot as plt #相当于c的宏定义
from wordcloud import WordCloud,STOPWORDS
text=""
f=open(r"File\word_cloud.txt","r")
li=f.readlines() #以"\n"为分隔符返回一个列表
for line i
这篇文章主要介绍了python根据文本生成词云图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
效果
代码
from wordcloud import WordCloud
import codecs
import jieba
#import jieba.analyse as analyse
from scipy.misc import imread
import os
from os import path
import matp