I am trying to form a word cloud for the tf-idf values:
Below are the tf-idf values in the dataframe. When I try to form a word cloud, the values with higher values, in this case "seat - 2.57" is shown in largest font. But I need the vice-versa. "Nice - 2.088" to have a bigger font as it is of higher importance.
[[u'nice' 2.0886619578149417]
[u'owl' 2.2729656758128876]
[u'person' 2.386294361119891]
[u'read' 2.455287232606842]
[u'seat' 2.5766480896111092]]
Below is the code:
print(top_10.values)
d = {}
for a, x in top_10.values:
d[a] = x
import matplotlib.pyplot as plt
from wordcloud import WordCloud
wordcloud = WordCloud()
wordcloud.generate_from_frequencies(frequencies=d)
plt.figure( figsize=(20,10) )
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
You can just use different frequencies to supply to the wordcloud.
Eg
d[a] = 3-x
or
d[a] = 1./x
Complete example:
top_10 = lambda :""
top_10.values = [[u'nice', 2.0886619578149417],
[u'owl', 2.2729656758128876],
[u'person', 2.386294361119891],
[u'read', 2.455287232606842],
[u'seat', 2.5766480896111092]]
d = {}
for a, x in top_10.values:
d[a] = 3-x
import matplotlib.pyplot as plt
from wordcloud import WordCloud
wordcloud = WordCloud()
wordcloud.generate_from_frequencies(frequencies=d)
plt.figure( figsize=(5,3) )
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.