python中stylecloud包的使用
stylecloud介绍
stylecloud是一款比较好用的python包,常用于数据可视化操作,具体的介绍看看别人写的吧
https://mp.weixin.qq.com/s/B23uDxzLUa_45uDh2R9Vlw
https://cloud.tencent.com/developer/article/1699651
蒙版图片参考网址:https://fontawesome.com/license/free
中文版:https://fa5.dashgame.com/#/%E5%9B%BE%E6%A0%87
配色:palettable: https://jiffyclub.github.io/palettable/
特别需要注意的是蒙版图片的调用: 例如:fa-grin-beam,在python中调用好像得改为fa.grin-beam才行,有时候都不行,还是得自己多试试,搞不懂。
下面是个实例: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37from stylecloud import gen_stylecloud
import jieba
import re
# 读取数据
with open('xxxx.txt', encoding='utf-8') as f:
data = f.read()
# 文本预处理 去除一些无用的字符 只提取出中文出来
new_data = re.findall('[\u4e00-\u9fa5]+', data, re.S)
new_data = "/".join(new_data)
# 文本分词
seg_list_exact = jieba.cut(new_data, cut_all=True)
result_list = []
with open('stopword.txt', encoding='utf-8') as f:
con = f.readlines()
stop_words = set()
for i in con:
i = i.replace("\n", "") # 去掉读取每一行数据的\n
stop_words.add(i)
for word in seg_list_exact:
# 设置停用词
if word not in stop_words and len(word) > 1:
result_list.append(word)
print(result_list)
gen_stylecloud(
text=' '.join(result_list), # 文本数据
size=600, # 词云图大小
font_path=r'C:\Windows\Fonts\msyh.ttc', # 中文词云 显示需要设置字体
output_name='词云12.png', # 输出词云图名称
icon_name='fas fa.grin-beam', # 图标 图片选择网址:https://fontawesome.com/license/free # https://fontawesome.dashgame.com/
# palette="Dark2_7" # 可以选择不同的配色方案,网址:palettable https://jiffyclub.github.io/palettable/
)