wordcloud3.py 731 B

1234567891011121314151617181920212223242526272829303132
  1. import csv
  2. from wordcloud import WordCloud
  3. #read first column of csv file to string of words seperated
  4. #by tab
  5. your_list = []
  6. with open('keyword2.csv', 'r') as f:
  7. reader = csv.reader(f)
  8. your_list = '\t'.join([i[1] for i in reader])
  9. # Generate a word cloud image
  10. wordcloud = WordCloud().generate(your_list)
  11. # Display the generated image:
  12. # the matplotlib way:
  13. import matplotlib.pyplot as plt
  14. plt.imshow(wordcloud, interpolation='bilinear')
  15. plt.axis("off")
  16. # lower max_font_size
  17. wordcloud = WordCloud(max_font_size=40).generate(your_list)
  18. plt.figure()
  19. plt.imshow(wordcloud, interpolation="bilinear")
  20. plt.axis("off")
  21. plt.show()
  22. # The pil way (if you don't have matplotlib)
  23. # image = wordcloud.to_image()
  24. # image.show()