Skip to content

Instantly share code, notes, and snippets.

@dzamlo
Created August 30, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dzamlo/ec5ab24bcce52d02fc455993a91cfb0d to your computer and use it in GitHub Desktop.
Save dzamlo/ec5ab24bcce52d02fc455993a91cfb0d to your computer and use it in GitHub Desktop.
import fileinput
import tokenize
import matplotlib.pyplot as plt
from wordcloud import WordCloud
if __name__ == '__main__':
# If some files don't have the same encoding, this is likely to not work correctly.
tokens = tokenize.tokenize(fileinput.input(mode='rb').readline)
tokens_no_string = (t for t in tokens if t.type not in [tokenize.ENCODING, tokenize.STRING])
tokens_lowercase_str = (t.string.lower() for t in tokens_no_string)
wordcloud = WordCloud().generate("\n".join(tokens_lowercase_str))
plt.imsave("/tmp/foo.png", wordcloud)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment