内容简介:stylecloud基于wordcloud库,使用方法更简单一些。该库的特点有csv为词频统计结果,两个字段,分别为今天准备了两个csv
预祝全国考生:鲤鱼跃龙门,门门考高分~
stylecloud基于wordcloud库,使用方法更简单一些。该库的特点有
-
支持词云图图标形状设置
-
可直接读取csv文件(csv有两列,word和freq)
-
可调色
-
...
安装
pip install stylecloud
数据
csv为词频统计结果,两个字段,分别为 word和freq 。
今天准备了两个csv
-
data/高考.csv
-
data/股市.csv
import pandas as pd
df1 = pd.read_csv('data/高考.csv')
df1.head()
| word | freq | |
|---|---|---|
| 0 | 高考 | 2198 |
| 1 | 未来 | 1549 |
| 2 | 决定 | 1443 |
| 3 | 一个 | 806 |
| 4 | 可以 | 644 |
df2 = pd.read_csv('data/股市.csv')
df2.head()
| word | freq | |
|---|---|---|
| 0 | 牛市 | 1993 |
| 1 | 图片 | 649 |
| 2 | 市场 | 530 |
| 3 | A股 | 527 |
| 4 | 股市 | 520 |
快速上手
import stylecloud
stopwords = open('data/stopwords.txt', encoding='utf-8').read().split('\n')
stylecloud.gen_stylecloud(file_path='data/高考.csv',
font_path='data/SourceHanSansCN-Regular.otf',
output_name='output/高考1.png',
size=500,
custom_stopwords=stopwords)
import stylecloud
stopwords = open('data/stopwords.txt', encoding='utf-8').read().split('\n')
stylecloud.gen_stylecloud(file_path='data/股市.csv',
font_path='data/SourceHanSansCN-Regular.otf',
output_name='output/股市1.png',
size=500,
custom_stopwords=stopwords)
stylecloud参数介绍
-
file_path:CSV的文件路径,需要注意的是csv文件格式为两列(word, freq)
-
size:词云图尺寸[默认值:512]
-
custom_stopwords:自定义停用词列表
-
output_name:输出的词云图路径
-
font_path:字体路径
-
icon_name:图标名(fas fa-iconname)只需要改iconname,[默认值: fas fa-flag]
-
palette:调色板(通过 palettable 实现)[默认值:cartocolors.qualitative.Bold_6]
-
background_color:词云图背景色[默认值:white]
-
max_font_size:词云图最大字号[默认值:200]
-
random_state:控制单词和颜色的随机状态,如不设置,每次运行的效果会发生变化
图形设置
icon_name参数的模板【fas fa-iconname】只需要改动iconname即可。
iconname并不是随便起的,必须能在https://fontawesome.com/license/free 搜到才可以。
比如以 高考 为例,我会在搜索框搜索跟 教育 相关的关键词
-
university
-
education 等
截图中找到最能体现文本主题的图标 user-graduate
所以icon_name = 'fas fa-user-graduate'
import stylecloud
stopwords = open('data/stopwords.txt', encoding='utf-8').read().split('\n')
stylecloud.gen_stylecloud(file_path='data/高考.csv',
font_path='data/SourceHanSansCN-Regular.otf',
output_name='output/高考2.png',
icon_name='fas fa-user-graduate',
size=500,
custom_stopwords=stopwords)
import stylecloud
stopwords = open('data/stopwords.txt', encoding='utf-8').read().split('\n')
stylecloud.gen_stylecloud(file_path='data/股市.csv',
font_path='data/SourceHanSansCN-Regular.otf',
output_name='output/股市2.png',
icon_name='fas fa-question-circle',
size=500,
custom_stopwords=stopwords)
往期文章
公众号后台回复关键词【stylecloud】即可下载本文数据代码
“ 分享 ”和“ 在看 ”是更好的支持!
以上所述就是小编给大家介绍的《stylecloud:简洁易用的词云库》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Introduction to Computation and Programming Using Python
John V. Guttag / The MIT Press / 2013-7 / USD 25.00
This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!