.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/arabic.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_arabic.py: Create wordcloud with Arabic ============================ Generating a wordcloud from Arabic text Dependencies: - bidi.algorithm - arabic_reshaper Dependencies installation: pip install python-bidi arabic_reshape .. GENERATED FROM PYTHON SOURCE LINES 14-36 .. rst-class:: sphx-glr-script-out .. code-block:: none | .. code-block:: Python import os import codecs from wordcloud import WordCloud import arabic_reshaper from bidi.algorithm import get_display # get data directory (using getcwd() is needed to support running example in generated IPython notebook) d = os.path.dirname(__file__) if "__file__" in locals() else os.getcwd() # Read the whole text. f = codecs.open(os.path.join(d, 'arabicwords.txt'), 'r', 'utf-8') # Make text readable for a non-Arabic library like wordcloud text = arabic_reshaper.reshape(f.read()) text = get_display(text) # Generate a word cloud image wordcloud = WordCloud(font_path='fonts/NotoNaskhArabic/NotoNaskhArabic-Regular.ttf').generate(text) # Export to an image wordcloud.to_file("arabic_example.png") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.399 seconds) .. _sphx_glr_download_auto_examples_arabic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: arabic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: arabic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: arabic.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_