Mercurial > hg > python
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:0a3abe59e364 | 2:e07789816ca5 |
---|---|
1 #!/usr/bin/env python | |
2 """ | |
3 Minimal Example | |
4 =============== | |
5 Generating a square wordcloud from a text file using default arguments. | |
6 """ | |
7 | |
8 import sys | |
9 from os import path | |
10 from wordcloud import WordCloud | |
11 from matplotlib import use | |
12 use('pdf') | |
13 | |
14 # Read the whole text. | |
15 text = open(sys.argv[1]).read() | |
16 | |
17 # Generate a word cloud image | |
18 wordcloud = WordCloud().generate(text) | |
19 | |
20 # Display the generated image: | |
21 # the matplotlib way: | |
22 import matplotlib.pyplot as plt | |
23 plt.imshow(wordcloud, interpolation='bilinear') | |
24 plt.axis("off") | |
25 | |
26 # lower max_font_size | |
27 wordcloud = WordCloud(max_font_size=40).generate(text) | |
28 plt.figure() | |
29 plt.imshow(wordcloud, interpolation="bilinear") | |
30 plt.axis("off") | |
31 plt.savefig('/tmp/cloud.pdf') |