JavaScript
x
2
1
my_list=["one", "one two", "three"]
2
and I am generating a word cloud for this list by using
JavaScript
1
2
1
wordcloud = WordCloud(width = 1000, height = 500).generate(" ".join(my_list))
2
As I am converting all the items into string it is generating word cloud for
JavaScript
1
4
1
"one","two","three"
2
3
But I want to generate word cloud for the values, "one","one two","three"
4
help me for generating word cloud for items in a list
Advertisement
Answer
one way of doing,
JavaScript
1
13
13
1
import matplotlib.pyplot as plt
2
from wordcloud import WordCloud
3
4
#convert list to string and generate
5
unique_string=(" ").join(my_list)
6
wordcloud = WordCloud(width = 1000, height = 500).generate(unique_string)
7
plt.figure(figsize=(15,8))
8
plt.imshow(wordcloud)
9
plt.axis("off")
10
plt.savefig("your_file_name"+".png", bbox_inches='tight')
11
plt.show()
12
plt.close()
13
Another way by creating Counter Dictionary,
JavaScript
1
12
12
1
#convert it to dictionary with values and its occurences
2
from collections import Counter
3
word_could_dict=Counter(my_list)
4
wordcloud = WordCloud(width = 1000, height = 500).generate_from_frequencies(word_could_dict)
5
6
plt.figure(figsize=(15,8))
7
plt.imshow(wordcloud)
8
plt.axis("off")
9
#plt.show()
10
plt.savefig('yourfile.png', bbox_inches='tight')
11
plt.close()
12