使用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 batter was not bitter. So 'twas good that Betty Botter bought some better butter.
生成云图代码:
#导入生成云图模块
from wordcloud import WordCloud
with open("F:/python入门/数据2/fenci_test2.txt" ,encoding="utf-8")as file:
#读取文本
text=file.read()
#设置词云的字体、背景颜色、宽、高、字数
wordcloud=WordCloud(font_path="C:/Windows/Fonts/Tahoma.ttf",
background_color="black",width=600,
height=300,max_words=50).generate(text)
#生成图片
image=wordcloud.to_image()
#显示图片
image.show()
结果:
您可能感兴趣的文章:Python通过文本和图片生成词云图Python实现Wordcloud生成词云图的示例Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解Python制作词云图代码实例如何用Python制作微信好友个性签名词云图利用Python爬取微博数据生成词云图片实例代码Python简单实现词云图代码及步骤解析