forked from codingprivacy/Feedback-Portal-System
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wordcloud_generate.py
39 lines (30 loc) · 1.09 KB
/
wordcloud_generate.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
import data_calculation
import itertools
from wordcloud import WordCloud, STOPWORDS
import matplotlib
import pandas as pd
matplotlib.use('Agg')
def generate_graph():
df=data_calculation.save_data()
comment_words = ' '
stopwords = set(STOPWORDS)
single_list=list(itertools.chain.from_iterable(df))
#print()
print(single_list)
for val in single_list:
val = str(val)
tokens = val.split()
for i in range(len(tokens)):
tokens[i] = tokens[i].lower()
for words in tokens:
comment_words = comment_words + words + ' '
#print(comment_words)
wordcloud = WordCloud(width = 800, height = 800,
background_color ='white',
stopwords = stopwords,
min_font_size = 10).generate(comment_words)
matplotlib.pyplot.figure(figsize = (6, 6), facecolor = None,frameon=False)
matplotlib.pyplot.imshow(wordcloud)
matplotlib.pyplot.axis("off")
matplotlib.pyplot.tight_layout(pad = 0)
matplotlib.pyplot.savefig('/var/www/FPSU/FPSU/static/images/wordcloud.png')