.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "sphinx_gallery_output/plot_03_as_wordcloud.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_sphinx_gallery_output_plot_03_as_wordcloud.py: Word clouds =========== To visualise subset contents (rather than sizes), use the :code:`as_wordcloud` constructors, which generate a word cloud using the word_cloud_ library. .. _word_cloud: https://github.com/amueller/word_cloud .. GENERATED FROM PYTHON SOURCE LINES 13-56 .. image-sg:: /sphinx_gallery_output/images/sphx_glr_plot_03_as_wordcloud_001.png :alt: plot 03 as wordcloud :srcset: /sphinx_gallery_output/images/sphx_glr_plot_03_as_wordcloud_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from matplotlib_set_diagrams import ( EulerDiagram, VennDiagram, ) text_1 = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.""" text_2 = """Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet.""" def word_tokenize(text): """Break a string into its constituent words, and convert the words into their 'standard' form (tokens). The procedure below is a poor-man's tokenization. Consider using the Natural Language Toolkit (NLTK) instead: >>> import nltk; words = nltk.word_tokenize(text) """ # get a word list words = text.split(' ') # remove non alphanumeric characters words = [''.join(ch for ch in word if ch.isalnum()) for word in words] # convert to all lower case words = [word.lower() for word in words] return words # Tokenize strings. sets = [set(word_tokenize(text)) for text in [text_1, text_2]] fig, (ax1, ax2) = plt.subplots(1, 2) EulerDiagram.as_wordcloud(sets, ax=ax1) VennDiagram.as_wordcloud(sets, ax=ax2) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.512 seconds) .. _sphx_glr_download_sphinx_gallery_output_plot_03_as_wordcloud.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_as_wordcloud.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_as_wordcloud.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_as_wordcloud.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_