-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_word_cloud.py
More file actions
30 lines (23 loc) · 823 Bytes
/
create_word_cloud.py
File metadata and controls
30 lines (23 loc) · 823 Bytes
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
# Basically the simple.py example from https://github.com/amueller/word_cloud
from os import path
from wordcloud import WordCloud, STOPWORDS
import sys
import json
import codecs
d = path.dirname(__file__)
print path.join(d, sys.argv[1])
json_data = codecs.open(path.join(d, sys.argv[1]), "r", "utf-8")
wordsDict = json.loads(json_data.read())
stopwords = set(STOPWORDS)
stopwords.add("posted")
stopwords.add("edited")
stopwords.add("just")
stopwords.add("like")
# Generate a word cloud image
wordcloud = WordCloud(width=1800, height=1200, margin=10, mode="RGBA", stopwords=stopwords).generate_from_frequencies(wordsDict)
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
wordcloud.to_file('./' + sys.argv[2] + '.png')