-
Notifications
You must be signed in to change notification settings - Fork 5
/
simple.py
38 lines (32 loc) · 926 Bytes
/
simple.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Minimal Example
===============
Generating a square wordcloud from the US constitution using default arguments.
"""
from os import path
from wordcloud import WordCloud
import os
d = path.dirname(__file__)
font=os.path.join(os.path.dirname(__file__), "DroidSansFallbackFull.ttf")
font='simhei.ttf'
# Read the whole text.
#text = open(path.join(d, 'constitution.txt')).read()
text = open(u"video.html").read().decode('gbk')
# Generate a word cloud image
wordcloud = WordCloud(font_path=font).generate(text)
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud)
plt.axis("off")
# lower max_font_size
wordcloud = WordCloud(font_path=font,max_font_size=40).generate(text)
plt.figure()
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
# The pil way (if you don't have matplotlib)
#image = wordcloud.to_image()
#image.show()