forked from program-spiritual/DataAnalysisInAction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.py
50 lines (42 loc) · 1.42 KB
/
demo2.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding:utf-8 -*-
import matplotlib
matplotlib.use('Qt4Agg')
from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
from PIL import Image
import numpy as np
# 生成词云
def create_word_cloud(f):
print('根据词频计算词云')
text = " ".join(jieba.cut(f, cut_all=False, HMM=True))
wc = WordCloud(
font_path="./SimHei.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()
if __name__ == '__main__':
f = '''数据分析全景图及修炼指南\
学习数据挖掘的最佳学习路径是什么?\
Python 基础语法:开始你的 Python 之旅\
Python 科学计算:NumPy\
Python 科学计算:Pandas\
学习数据分析要掌握哪些基本概念?\
用户画像:标签化就是数据的抽象能力\
数据采集:如何自动化采集数据?\
数据采集:如何用八爪鱼采集微博上的“D&G”评论?\
Python 爬虫:如何自动化下载王祖贤海报?\
数据清洗:数据科学家 80% 时间都花费在了这里?\
数据集成:这些大号一共 20 亿粉丝?\
数据变换:大学成绩要求正态分布合理么?\
数据可视化:掌握数据领域的万金油技能\
一次学会 Python 数据可视化的 10 种技能'''
create_word_cloud(f)