.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/simple.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_simple.py: Minimal Example =============== Generating a square wordcloud from the US constitution using default arguments. .. GENERATED FROM PYTHON SOURCE LINES 8-67 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_simple_001.png :alt: simple :srcset: /auto_examples/images/sphx_glr_simple_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_simple_002.png :alt: simple :srcset: /auto_examples/images/sphx_glr_simple_002.png :class: sphx-glr-multi-img .. code-block:: Python import os from os import path from wordcloud import WordCloud # get data directory (using getcwd() is needed to support running example in generated IPython notebook) d = path.dirname(__file__) if "__file__" in locals() else os.getcwd() # Read the whole text. text = open(path.join(d, 'werewolf.txt')).read() # Generate a word cloud image wordcloud = WordCloud(width=1600,height=900).generate(text) # Display the generated image: # the matplotlib way: import matplotlib.pyplot as plt plt.imshow(wordcloud, interpolation='bilinear') plt.axis("off") stop_words = {"wouldn't", 'between', "why's", 'know', 'over', "you'll", "we'd", "shouldn't", 'these', 'until', 'himself', 'no', "aren't", 'too', "doesn't", "here's", 'monsterdondoublefeature', 'or', 'theirs', "he'll", 'very', "you're", "hasn't", "when's", 'above', 'does', 'off', "where's", 'under', "hadn't", 'film', "didn't", 'it', 'any', 'he', 'http', 'such', 'got', 'wolfen1981', 'be', 'this', 'to', "we're", "who's", 'howling11985', 'www', 'a', 'not', "he'd", 'ours', 'you', 'his', 'would', 'then', "there's", 'out', 'so', 'my', "i'm", 'was', 'after', 'whom', 'we', 'your', 'all', 'about', 'ever', 'had', 'how', 'hers', 'other', 'up', "i'll", "i've", 'during', 'therefore', 'while', "we've", "she's", 'can', 'their', "don't", 'since', 'did', 'once', "she'd", 'they', 'than', 'like', 'good', "you've", "they'd", 'are', 'her', "you'd", 'ourselves', 'movie', 'themselves', 'really', 'cannot', 'she', 'more', 'however', 'do', 'going', 'when', 'with', 'our', "we'll", 'com', 'have', 'the', 'yeah', "let's", 'those', 'them', "wasn't", 'which', 'why', 'yourselves', 'been', 'who', 'being', 'most', 'get', "mustn't", "what's", 'also', 'me', 'watch', 'its', 'again', "haven't", "she'll", 'yours', 'that', 'as', 'before', 'hence', 'of', 'monstermiru', "they're", 'few', 'were', 'now', "isn't", 'one', 'both', 'well', "weren't", 'could', 'if', "how's", 'there', 'am', 'because', 'see', 'further', 'wulfen1981', 'is', 'ought', 'herself', "they've", 'i', 'own', 'into', 'what', 'same', 'guy', 'otherwise', 'yourself', "couldn't", 'monsterdon', "it's", "i'd", 'wrongwolfen', 'nor', 'from', 'by', 'should', 'an', 'some', 'myself', 'where', 'down', 'shall', 'else', 'at', 'for', 'here', 'movies', 'against', 'through', "they'll", 'in', 'on', "that's", 'has', "he's", 'doing', "won't", 'but', 'r', 'him', 'films', 'itself', 'and', 'having', 'each', 'only', "can't", 'k', 'just', "shan't", 'below'} # lower max_font_size wordcloud = WordCloud(max_font_size=40, stopwords=stop_words, ).generate(text) plt.figure(figsize=(13, 9)) plt.imshow(wordcloud, interpolation="bilinear") plt.axis("off") plt.savefig('werewolf.png', format="png") # The pil way (if you don't have matplotlib) # image = wordcloud.to_image() # image.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.358 seconds) .. _sphx_glr_download_auto_examples_simple.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: simple.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: simple.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: simple.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_