##### >>What's Word Cloud


词云 (Word Cloud)是对文本中出现频率较高的词语给予视觉化展示的图形, 是一种常见的文本挖掘的方法。目前已有多种数据分析工具支持这种图形,如Matlab, SPSS, SAS, R 和 Python 等等,也有很多在线网页能生成 word cloud, 例如wordclouds.com

##### >> Create Word Cloud via Python


Python 可以使用 wordcloud 模块来生成词云。

  1. 安装 wordcloud, matplotlib 及其依赖模块。

  2. 准备文本。

我从维基百科中找到一段关于 Word Cloud History 的文字,以下将以这段文字为例。复制这段文字到 NotePad,并将其保存为 .*txt 文本格式。

  1. 运行 Python script。
"""
Python Example
===============
Generating a wordcloud from the txt file using Python.
""" from wordcloud import WordCloud # Read the whole text from txt.
fp = "C:/Users/yuki/Desktop/WordCloudHistory.txt"
text = open(fp).read() # Generate a word cloud image
wordcloud = WordCloud(
font_path = "C:/Windows/Fonts/BROADW.TTF",
width = 600, #width of the canvas.
height = 400, #height of the canvas.
max_font_size = 60,
font_step = 1,
background_color = "white",
random_state = 1,
margin = 2,
colormap = "tab20" #matplotlib colormap
).generate(text) # Display the generated image in matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
  1. 生成 word cloud。

##### >> Notes


在使用 wordcloud 模块的时候曾发现某些词语的频率(或者权重)是一样的,但是在生成的图形中字体大小却不一样。

Google 后找到开发作者的回答:

wordcloud document

The algorithm might give more weight to the ranking of the words than their actual frequencies, depending on the max_font_size and the scaling heuristic.

github issues

The scaling is relative to the size of the figure and the frequency of the words. The frequencies are normalized against the max frequency, so the absolute values are irrelevant.

大概是为了将词语尽可能地填满画布,wordcloud 算法会自动根据 max_font_size 和 scale 自动调整词语的权重。那么 wordcloud 生成的图形词语大小和他的词频(或者权重)的绝对值并不是一一对应的关系。

我觉得嘛:虽然这样画出的图形比较好看,但还是觉得有点奇怪,毕竟按词频大小展示词语应该是 word cloud 这种图形的精髓。

##### >> Sample Code


download here

>> Related Blogs

1. [Word Cloud (词云) - JavaScript](https://www.cnblogs.com/yukiwu/p/10968816.html)
2. [Word Cloud (词云) - R](https://www.cnblogs.com/yukiwu/p/10969250.html)
3. [Word Cloud (词云) - Matlab](https://www.cnblogs.com/yukiwu/p/10971998.html)

Word Cloud (词云) - Python的更多相关文章

  1. Word Cloud (词云) - Matlab

    今天要总结的是 Word Cloud 最后一个部分了,用 Matlab 来创建 word cloud.Matlab R2018b 已经提供 wordcloud 函数可以直接生成词云了. >> ...

  2. Word Cloud (词云) - R

    在前面已经陆续总结了如何用 Python 和 JavaScript 创建词云了,今天要说的是 R.其实 SPSS 和 SAS 的 Word Cloud 扩展模板都是基于 R 实现的. >> ...

  3. Word Cloud (词云) - JavaScript

    在上一篇中已经分享了用 Python 创建词云了.接下来继续总结其他创建词云的方法. >> Create Word Cloud via JavaScript JavaScript 可以借助 ...

  4. 从CentOS安装完成到生成词云python学习日记

    欢迎访问我的个人博客:原文链接 前言 人生苦短,我用python.学习python怎么能不搞一下词云呢是不是(ง •̀_•́)ง 于是便有了这篇边实践边记录的笔记. 环境:VMware 12pro + ...

  5. 根据词频生成词云(Python wordcloud实现)

    网上大多数词云的代码都是基于原始文本生成,这里写一个根据词频生成词云的小例子,都是基于现成的函数. 另外有个在线制作词云的网站也很不错,推荐使用:WordArt 安装词云与画图包 pip3 insta ...

  6. python 生成18年写过的博客词云

    文章链接:https://mp.weixin.qq.com/s/NmJjTEADV6zKdT--2DXq9Q 回看18年,最有成就的就是有了自己的 博客网站,坚持记录,写文章,累计写了36篇了,从一开 ...

  7. 爬虫之绘图matplotlib与词云(七)

    1 绘制条形图 import matplotlib # 数据可视化 from matplotlib import pyplot as plt # 配置字体 matplotlib.rcParams[&q ...

  8. Matplotlib学习---用wordcloud画词云(Word Cloud)

    画词云首先需要安装wordcloud(生成词云)和jieba(中文分词). 先来说说wordcloud的安装吧,真是一波三折.首先用pip install wordcloud出现错误,说需要安装Vis ...

  9. 推荐一个免费的生成词云(word cloud)的在线工具

    "词云"这个概念由美国西北大学新闻学副教授.新媒体专业主任里奇·戈登(Rich Gordon)提出. "词云"就是对网络文本中出现频率较高的"关键词& ...

随机推荐

  1. 下载数据到Excel,工具类

    使用反射将model数据下载到Excel中 package test.upload.utils; import java.lang.reflect.Method; import java.math.B ...

  2. CentOS 6.x Inotify+Rsync

    CentOS 6.x Inotify+Rsync yum -y install lrzsz [root@rsync ~]# mount -t nfs 10.6.100.75:/volume1/pace ...

  3. 2003 -Can't connection to mysql server on | navicat for mysql Access denied for user 'root'@''ip'(using password :yes)

    用本机windows上的Navicat for mysql链接虚拟机Linux的mysql数据库时,第一次连接的时候报的错误是 2003 -Can't connection to mysql serv ...

  4. [TypeScript] Query Properties with keyof and Lookup Types in TypeScript

    The keyof operator produces a union type of all known, public property names of a given type. You ca ...

  5. Visual Studio VS如何修改代码字体

    工具-选项-环境-字体和颜色

  6. 解决UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordinal not in range(128)的编码问题

    当我在运行一个基于scrapy的爬虫时出现UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordina ...

  7. Socketclient与服务端

    package test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamR ...

  8. hdoj2680 Choose the best route

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

  9. Android经常使用设计模式(二)

    继上一篇 Android经常使用设计模式(一)里认识了观察者.适配器.代理等三种模式,这一篇将会解说下面三种模式: 工厂模式 单例模式 命令模式 1.工厂模式(Factory Pattern) 工厂模 ...

  10. [Sciter] 资源引用

    http://www.cnblogs.com/yinxufeng/p/fb343eecda564aa63bce0bdf15709ddf.html 方式一. 加载外部文件方式二. 加载内存方式三. 加载 ...