Commit b35ed472 authored by Andreas Mueller's avatar Andreas Mueller
Browse files

add the "pil way" of showing an image to the simple.py

parent ea578eb1
...@@ -6,15 +6,19 @@ Generating a square wordcloud from the US constitution using default arguments. ...@@ -6,15 +6,19 @@ Generating a square wordcloud from the US constitution using default arguments.
""" """
from os import path from os import path
import matplotlib.pyplot as plt
from wordcloud import WordCloud from wordcloud import WordCloud
d = path.dirname(__file__) d = path.dirname(__file__)
# Read the whole text. # Read the whole text.
text = open(path.join(d, 'constitution.txt')).read() text = open(path.join(d, 'constitution.txt')).read()
# Generate a word cloud image
wordcloud = WordCloud().generate(text) wordcloud = WordCloud().generate(text)
# Open a plot of the generated image.
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud) plt.imshow(wordcloud)
plt.axis("off") plt.axis("off")
...@@ -24,3 +28,7 @@ plt.figure() ...@@ -24,3 +28,7 @@ plt.figure()
plt.imshow(wordcloud) plt.imshow(wordcloud)
plt.axis("off") plt.axis("off")
plt.show() plt.show()
# The pil way (if you don't have matplotlib)
#image = wordcloud.to_image()
#image.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment