Mercurial > hg > python
diff simpleCloud.py @ 2:e07789816ca5
adding more python files from lib/python on origen
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Mon, 09 Mar 2020 16:48:09 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simpleCloud.py Mon Mar 09 16:48:09 2020 +0000 @@ -0,0 +1,31 @@ +#!/usr/bin/env python +""" +Minimal Example +=============== +Generating a square wordcloud from a text file using default arguments. +""" + +import sys +from os import path +from wordcloud import WordCloud +from matplotlib import use +use('pdf') + +# Read the whole text. +text = open(sys.argv[1]).read() + +# Generate a word cloud image +wordcloud = WordCloud().generate(text) + +# Display the generated image: +# the matplotlib way: +import matplotlib.pyplot as plt +plt.imshow(wordcloud, interpolation='bilinear') +plt.axis("off") + +# lower max_font_size +wordcloud = WordCloud(max_font_size=40).generate(text) +plt.figure() +plt.imshow(wordcloud, interpolation="bilinear") +plt.axis("off") +plt.savefig('/tmp/cloud.pdf')