用Python生成“数据可视化云图”(WordCloud using Python)
发布日期:2021-06-30 22:58:32
浏览次数:2
分类:技术文章
本文共 1782 字,大约阅读时间需要 5 分钟。
Github下载链接:https://github.com/nikhilkumarsingh/wordcloud-example
youtube视频链接:https://www.youtube.com/watch?v=95p3cVkqYHQ
What is a wordcloud?
什么是文字云图?
An image composed of words used in a particular text or subject, in which the size of each word indicates its frequency or importance.
由在特定文本或主题中使用的单词组成的图像,其中每个单词的大小表示其频率或重要性。
Installation
安装
Install wordcloud using a simple pip command.
使用简单的pip命令安装wordcloud。pip install wordcloudwikipedia library is used for extracting wikipedia articles on any given topic. Install it using this pip command:
维基百科库用于提取有关任何给定主题的维基百科文章。使用以下pip命令安装它:
pip install wikipediaUsage Run python script as: 用法 以如下方式运行python脚本:
python mywc.py
For example:
例如:python mywc.py China
will create wordcloud for the topic ‘china’ which looks like this:
将为主题“China”创建wordcloud,如下所示:
program:
程序:
import sysfrom os import pathimport numpy as npfrom PIL import Imageimport wikipediafrom wordcloud import WordCloud, STOPWORDS# get path to script's directorycurrdir = path.dirname(__file__)def get_wiki(query): # get best matching title for given query title = wikipedia.search(query)[0] # get wikipedia page for selected title page = wikipedia.page(title) return page.contentdef create_wordcloud(text): # create numpy araay for wordcloud mask image mask = np.array(Image.open(path.join(currdir, "cloud.png"))) # create set of stopwords stopwords = set(STOPWORDS) # create wordcloud object wc = WordCloud(background_color="white", max_words=200, mask=mask, stopwords=stopwords) # generate wordcloud wc.generate(text) # save wordcloud wc.to_file(path.join(currdir, "wc.png"))if __name__ == "__main__": # get query query = sys.argv[1] # get text for given query text = get_wiki(query) # generate wordcloud create_wordcloud(text)
云图素材
转载地址:https://lukeyalvin.blog.csdn.net/article/details/104076371 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月12日 17时49分03秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【linux用户模块】/etc/passwd的字段含义
2019-05-01
【linux用户模块】用户/用户组的管理
2019-05-01
【大数据】【调度】Airflow 和 Azkaban的选型
2019-05-01
Elasticseach之Linux单节点部署
2019-05-01
Elasticseach之Linux集群部署
2019-05-01
Elasticsearch相关核心概念
2019-05-01
Elasticsearch进阶之故障转移、水平扩容,倒排索引,分析器等
2019-05-01
Spring Data集成Elasticsearch
2019-05-01
Elasticsearch优化
2019-05-01
Elasticsearch相关问题
2019-05-01
k8s部署微服务
2019-05-01
k8s部署vue项目
2019-05-01
MapReduce之Hadoop序列化,MapTask 工作机制,CombineTextInputFormat 切片机制,Partition 分区,WritableComparable 排序
2019-05-01
Android屏幕适配方案,简单,便捷(最大宽度适配 Smallest Width)
2019-05-01
Android 开发基于Webview 自制一个简单的手机浏览器
2019-05-01