-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordcloudplotter.py
More file actions
32 lines (24 loc) · 1 KB
/
wordcloudplotter.py
File metadata and controls
32 lines (24 loc) · 1 KB
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
"""
Plot wordclouds based on this data camp tutorial: https://www.datacamp.com/community/tutorials/wordcloud-python
"""
import numpy as np
import pandas as pd
from os import path
from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
import matplotlib.pyplot as plt
def plot_word_cloud(text, q):
"""Plot word cloud. Based on this data camp tutorial: https://www.datacamp.com/community/tutorials/wordcloud-python"""
# Create stopword list:
stopwords = set(STOPWORDS)
#stopwords.update([])
# Generate a word cloud image
wordcloud = WordCloud(stopwords=stopwords, background_color="white").generate(text)
# Create and generate a word cloud image:
#wordcloud = WordCloud(max_font_size=50, max_words=100, background_color="white").generate(text)
# Display the generated image:
plt.figure(figsize=[12,12])
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
plt.savefig("fig/wordcloud_%s.png" % q)