forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (29 loc) · 953 Bytes
/
main.py
File metadata and controls
36 lines (29 loc) · 953 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
31
32
33
34
35
36
import matplotlib.pyplot as plt
from wordcloud import WordCloud
class QuickWordCloud:
def __init__(self, file_name="./data/test_data.txt"):
self.file_name = file_name
def extract_words(self):
all_words = ""
with open(self.file_name) as file:
data = file.read()
words = data.split()
words_lower = [w.lower() for w in words]
all_words += " ".join(words_lower) + " "
return all_words
def create_word_cloud(self, text):
wordcloud = WordCloud(
width=1600,
height=800,
background_color="white",
collocations=False,
repeat=True,
).generate(text)
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
if __name__ == "__main__":
wc = QuickWordCloud()
words = wc.extract_words()
wc.create_word_cloud(words)