Skip to content

Commit 28e1f64

Browse files
committed
词云Demo
1 parent 4c90c46 commit 28e1f64

13 files changed

Lines changed: 65 additions & 51 deletions

File tree

PythonDemo/.spyproject/workspace.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ save_non_project_files = False
66

77
[main]
88
version = 0.1.0
9-
recent_files = ['E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4JokeToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xlwtDemo.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xwltDemo2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4quickstart.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4Meizitu.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\urllib.requestDemo1.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixin.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinItchatSexAs.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotGroup.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotSingle.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYun.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\qqbotRobot.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinQianming.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arrayboolean.py', 'D:\\Anaconda3\\lib\\site-packages\\matplotlib\\pyplot.py']
9+
recent_files = ['E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4JokeToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xlwtDemo.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\saveToExcel\\xwltDemo2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYunToExcel2.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4quickstart.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4Meizitu.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\urllib.requestDemo1.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixin.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinItchatSexAs.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotGroup.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotSingle.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\bs4WangYiYun.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\qqbotRobot.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinQianming.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arrayboolean.py', 'D:\\Anaconda3\\lib\\site-packages\\matplotlib\\pyplot.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\simple.py', 'D:\\Anaconda3\\lib\\site-packages\\wordcloud\\__init__.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\a_new_hope.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\a_new_hope.txt', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\colored_by_group.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\emoji.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\frequency.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\happy-emoji.txt', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\masked.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\readme.txt', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\colored.py', 'D:\\Anaconda3\\lib\\site-packages\\PIL\\Image.py']
1010

PythonDemo/Matplotlib/demo.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Mar 14 10:13:32 2018
4+
5+
@author: Administrator
6+
"""
7+
8+
9+
import matplotlib.pyplot as plt
10+
from skimage import data
11+
img=data.astronaut()
12+
plt.imshow(img)
13+
plt.show()
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Mar 14 10:23:43 2018
4+
5+
@author: Administrator
6+
"""
7+
8+
import numpy as np
9+
import matplotlib.pyplot as plt
10+
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
11+
C,S = np.cos(X), np.sin(X)
12+
plot(X,C)
13+
plot(X,S)
14+
show()

PythonDemo/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wordcloud词云 jieba分词 itchat wxpy微信相关

PythonDemo/spider/QR.png

712 Bytes
Loading

PythonDemo/spider/weixinItchatSexAs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
friends = itchat.get_friends(update=True)
1414
sexs = list(map(lambda x: x['Sex'], friends[1:]))
1515
counts = list(map(lambda x: x[1], Counter(sexs).items()))
16-
labels = ['Unknow','Male', 'Female']
16+
labels = ['Male','FeMale', 'Unknown']
1717
colors = ['red', 'yellowgreen', 'lightskyblue']
1818
plt.figure(figsize=(8, 5), dpi=80)
1919
plt.axes(aspect=1)
-324 Bytes
Loading

PythonDemo/wordcloud/examples/a_new_hope.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Using custom colors
44
===================
55
6-
Using the recolor method and custom coloring functions.
6+
使用重新着色方法和自定义着色功能。
77
"""
88

99
import numpy as np
@@ -21,28 +21,24 @@ def grey_color_func(word, font_size, position, orientation, random_state=None,
2121

2222
d = path.dirname(__file__)
2323

24-
# read the mask image
25-
# taken from
26-
# http://www.stencilry.org/stencils/movies/star%20wars/storm-trooper.gif
24+
# 读取图片(图片来源:http://www.stencilry.org/stencils/movies/star%20wars/storm-trooper.gif)
2725
mask = np.array(Image.open(path.join(d, "stormtrooper_mask.png")))
2826

29-
# movie script of "a new hope"
30-
# http://www.imsdb.com/scripts/Star-Wars-A-New-Hope.html
31-
# May the lawyers deem this fair use.
27+
# 文字来源:“新希望”电影剧本(网址:http://www.imsdb.com/scripts/Star-Wars-A-New-Hope.html)
3228
text = open(path.join(d, 'a_new_hope.txt')).read()
3329

34-
# preprocessing the text a little bit
30+
# 预处理一点点文本
3531
text = text.replace("HAN", "Han")
3632
text = text.replace("LUKE'S", "Luke")
3733

38-
# adding movie script specific stopwords
34+
# 添加电影剧本特定的停用词
3935
stopwords = set(STOPWORDS)
4036
stopwords.add("int")
4137
stopwords.add("ext")
4238

4339
wc = WordCloud(max_words=1000, mask=mask, stopwords=stopwords, margin=10,
4440
random_state=1).generate(text)
45-
# store default colored image
41+
# 存储默认的彩色图像
4642
default_colors = wc.to_array()
4743
plt.title("Custom colors")
4844
plt.imshow(wc.recolor(color_func=grey_color_func, random_state=3),
10.4 KB
Loading

PythonDemo/wordcloud/examples/colored.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22
"""
33
Image-colored wordcloud
44
=======================
5+
您可以在ImageColorGenerator中实现使用基于图像的着色策略对文字云进行着色,它使用由源图像中的单词占用的区域的平均颜色。
56
6-
You can color a word-cloud by using an image-based coloring strategy
7-
implemented in ImageColorGenerator. It uses the average color of the region
8-
occupied by the word in a source image. You can combine this with masking -
9-
pure-white will be interpreted as 'don't occupy' by the WordCloud object when
10-
passed as mask.
11-
If you want white as a legal color, you can just pass a different image to
12-
"mask", but make sure the image shapes line up.
137
"""
148

159
from os import path
@@ -21,32 +15,31 @@
2115

2216
d = path.dirname(__file__)
2317

24-
# Read the whole text.
18+
# 读取整个文本
2519
text = open(path.join(d, 'alice.txt')).read()
2620

27-
# read the mask / color image taken from
28-
# http://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010
21+
# 读取蒙板/彩色图像(图片是从http://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010下载的)
2922
alice_coloring = np.array(Image.open(path.join(d, "alice_color.png")))
3023
stopwords = set(STOPWORDS)
3124
stopwords.add("said")
3225

3326
wc = WordCloud(background_color="white", max_words=2000, mask=alice_coloring,
3427
stopwords=stopwords, max_font_size=40, random_state=42)
35-
# generate word cloud
28+
# 生成词云
3629
wc.generate(text)
3730

38-
# create coloring from image
31+
# 从图像创建着色
3932
image_colors = ImageColorGenerator(alice_coloring)
4033

41-
# show
34+
# 显示
4235
plt.imshow(wc, interpolation="bilinear")
43-
plt.axis("off")
36+
plt.axis("off") #不显示坐标尺寸
4437
plt.figure()
45-
# recolor wordcloud and show
46-
# we could also give color_func=image_colors directly in the constructor
38+
# 重新着色词云并显示
39+
# 我们也可以直接在构造函数中给使用:color_func=image_colors
4740
plt.imshow(wc.recolor(color_func=image_colors), interpolation="bilinear")
48-
plt.axis("off")
41+
plt.axis("off") #不显示坐标尺寸
4942
plt.figure()
5043
plt.imshow(alice_coloring, cmap=plt.cm.gray, interpolation="bilinear")
51-
plt.axis("off")
52-
plt.show()
44+
plt.axis("off") #不显示坐标尺寸
45+
plt.show()#一次绘制三张图

0 commit comments

Comments
 (0)