前言

当我们想快速了解书籍、小说、电影剧本中的内容时,可以绘制 WordCloud 词云图,显示主要的关键词(高频词),可以非常直观地看到结果

核心代码

from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
from PIL import Image
import numpy as np # 生成词云函数
def create_word_cloud(words):
# 使用结巴分词
text = " ".join(jieba.cut(words,cut_all=False, HMM=True))
wc = WordCloud(
font_path="./wc.ttf",
max_words=100,
width=2000,
height=1200,
)
wordcloud = wc.generate(text)
# 写词云图片
wordcloud.to_file("wordcloud.jpg")
# 显示词云文件
plt.imshow(wordcloud)
plt.axis("off")
plt.show()

测试

ok,现在我们来传入一段文字,生成词云图片分析一下

s= """
1.life lies in movement. 生命在于运动
2.sport is the source of all life. 运动是生命的源泉.
3.to keep on, day after day practice go down, and only activities to keep the enthusiasm of adequate training and improve motor skills.
日复一日地坚持练下去吧,只有活动适量才能保持训练的热情和提高运动的技能.——塞涅卡
4.activity is the basis of life! 活动是生活的基础!——歌德
5.people's sound, not only by foods, especially to rely on motion.人的健全,不但靠饮食,尤靠运动.
6.the olympic motto is "higher, faster, stronger." 奥林匹克的格言是“更高,更快,更强”.
7.the health of the body for motionless and destruction, for sports practice and keep for a long time. --socrates 身体的健康因静止不动而破坏,因运动练习而长期保持.——苏格拉底
chenqionghe
chenqionghe
chenqionghe
chenqionghe
chenqionghe
muscle
muscle
muscle
muscle
muscle
yeah buddy! light weight baby
yeah buddy! light weight baby
yeah buddy! light weight baby
chenqionghe, go to the gym,yeah buddy! light weight baby
I was in the gym lifting weights.
"""
create_word_cloud(s)

运行结果如下

分析这张图片,不难看出:chenqionghe喜欢运动,有肌肉,light weight baby !

python绘制WordCloud词云图的更多相关文章

  1. python绘制中文词云图

    准备工作 主要用到Python的两个第三方库 jieba:中文分词工具 wordcloud:python下的词云生成工具 步骤 准备语料库,词云图需要的背景图片 使用jieba进行分词,去停用词,词频 ...

  2. 吃瓜的正确姿势,Python绘制罗志祥词云图

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 这篇文章中向大家介绍了Python绘制词云的方法,不难看出绘制词云可以说是一 ...

  3. python 制作wordcloud词云

    pip install wordcloud 需要用到numpy  pillow matplotlib 安装完成以后 wordcloud_cli --text in.txt --imagefile ou ...

  4. (数据科学学习手札71)在Python中制作个性化词云图

    本文对应脚本及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 一.简介 词云图是文本挖掘中用来表征词频的数据可视化 ...

  5. 用Python制作酷炫词云图,原来这么简单!

    一.简介词云图是文本挖掘中用来表征词频的数据可视化图像,通过它可以很直观地展现文本数据中地高频词:! 图1 词云图示例 在Python中有很多可视化框架可以用来制作词云图,如pyecharts,但这些 ...

  6. CVPR2018关键字分析生成词云图与查找

    今日目标:爬取CVPR2018论文,进行分析总结出提到最多的关键字,生成wordCloud词云图展示,并且设置点击后出现对应的论文以及链接 对任务进行分解: ①爬取CVPR2018的标题,简介,关键字 ...

  7. 用Python和WordCloud绘制词云(内附让字体清晰的秘笈)

    环境及模块: Win7 64位 Python 3.6.4 WordCloud 1.5.0 Pillow 5.0.0 Jieba 0.39 目标: 绘制安徽省2018年某些科技项目的词云,直观展示热点. ...

  8. python词云图之WordCloud

    1. 导入需要的包package import matplotlib.pyplot as plt from scipy.misc import imread from wordcloud import ...

  9. Python模块---Wordcloud生成词云图

    wordcloud是Python扩展库中一种将词语用图片表达出来的一种形式,通过词云生成的图片,我们可以更加直观的看出某篇文章的故事梗概. 首先贴出一张词云图(以哈利波特小说为例): 在生成词云图之前 ...

随机推荐

  1. 【模板】凸包向内推进求不严格的半平面交——poj3384

    想不明白这题写严格的半平面交为什么会错 /* 凸包所有边向内推进r */ #include<iostream> #include<cstring> #include<cs ...

  2. same-security-traffic

    关于Inter-interface和intra-interface: 要允许具有相同安全级别的接口之间的通信,或允许流量进入和退出同一接口,请在全局配置模式下使用same-security-traff ...

  3. WLC开机卡在launching....(变砖)

    1.出现故障的原因:A.通过手动更换镜像导致Boot Loader Menu Run primary image (7.0.220.0) - ActiveRun backup image (7.0.2 ...

  4. bootstrap标记说明

    <span class="caret"> 这就是 一个倒三角

  5. Esp32的一些资料链接

    http://wiki.ai-thinker.com/doku.php/utils/esp32_idf_menuconfig   http://wiki.ai-thinker.com/doku.php ...

  6. [A]List`1[MyObject] cannot be cast to [B]List`1[MyObject]

    Description I have created a small class in a single ASP.NET 4.5 web forms page that is instantiated ...

  7. CSS - 表格细线边框

    通过 border-collapse: collapse cellpadding="0", cellspacing= "0" 实现 <!DOCTYPE h ...

  8. 重新理解《务实创业》---HHR计划--以太一堂第三课

    第一节:开始学习 1,面对创业和融资,我们应该如何从底层,理解他们的本质呢?(实事求是) 2,假设你现在要出来融资,通常你需要告诉投资人三件事:我的市场空间很大,我的用户需求很疼,我的商业模式能跑通. ...

  9. 电影推荐算法---HHR计划

    1,先看FM部分. 2,看看冷启动. 0,热门召回源. 1,男女召回源,年龄召回源,职业召回源,score最高. 2,男女年龄职业相互组合: 3,存入redis.天级别更新. 3,召回+排序先搞懂. ...

  10. Lesson 15 Secrecy in industry

    Why is secrecy particularly important in the chemical industries? Two factors weigh heavily against ...