-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWordCloud.py
34 lines (29 loc) · 1.02 KB
/
WordCloud.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
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
import numpy as np
from PIL import Image
import pandas as pd
import random
def file():
DataSet = pd.read_csv("G:\\OneDrive - University of Edinburgh\\Poem Generation\\WebScrapping-PoetryFoundation\\PoetryFoundationData.csv")
tags = DataSet["Tags"]
tags = tags.dropna()
string =""
#print(tags)
for i in tags:
string = string+i
return string
def grey_color_func(word, font_size, position, orientation, random_state=None,
**kwargs):
return "hsl(0, 0%%, %d%%)" % random.randint(60, 100)
def create_word_cloud(string):
maskArray = np.array(Image.open("bookmask.png"))
cloud = WordCloud(background_color = "black", mask=maskArray,width=1280,height=720,scale=2, max_words = 200, stopwords = set(STOPWORDS), color_func=grey_color_func)
cloud.generate(string)
cloud.to_file("wordCloud.png")
pass
def main():
string = file()
create_word_cloud(string)
if __name__ == '__main__':
main()