-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud.py
More file actions
31 lines (25 loc) · 762 Bytes
/
Copy pathcloud.py
File metadata and controls
31 lines (25 loc) · 762 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
from wordcloud import WordCloud, STOPWORDS
from os import path
import matplotlib.pyplot as plt
def cloud(textfile):
d = path.dirname(__file__)
text = open(path.join(d, textfile + '.txt'), encoding='UTF-8').read()
filter_title = textfile
stopwords = set(STOPWORDS)
stopwords.add("RT")
stopwords.add("CO")
stopwords.add("HTTPS")
stopwords.add("AMP")
stopwords.add("RETWEET")
stopwords.add(filter_title)
wordcloud = WordCloud(max_font_size=60, stopwords=stopwords)
wordcloud.generate(text)
stopwords.remove(filter_title)
plt.figure()
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
def main():
cloud(textfile='ObamaCare')
if __name__ == '__main__':
main()