.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` 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 .. rst-class:: sphx-glr-script-out Out: .. code-block:: none | .. code-block:: default 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 1.006 seconds) .. _sphx_glr_download_auto_examples_arabic.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: arabic.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: arabic.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_