Word cloud is a nice library for generating fun plots with names. Here is an example I've used to generate the cloud with my name. You need to install python-arabic-reshaper, word cloud, matplotlib, python-bidi and numpy libraries to generate the plots.
You need to install the font NotoNaskhArabic-Regular.ttf (https://github.com/frappe/fonts/blob/master/usr_share_fonts/noto/NotoNaskhArabic-Regular.ttf). This example is used in macOS.
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from bidi.algorithm import get_display
from arabic_reshaper import ArabicReshaper
configuration = {
"language": "Urdu"
}
reshaper = ArabicReshaper(configuration=configuration)
text = reshaper.reshape("عرفان")
text = get_display(text)
x, y = np.ogrid[:300, :300]
mask = (x - 150) ** 2 + (y - 150) ** 2 > 130 ** 2
mask = 255 * mask.astype(int)
wc = WordCloud(background_color="white",font_path='/Users/mirfan/Library/Fonts/NotoNaskhArabic-Regular.ttf', repeat=True, mask=mask)
wc.generate(text)
plt.axis("off")
plt.imshow(wc, interpolation="bilinear")
plt.savefig("irfan.png")
Check it out and make cloud with your name.
Nice !!1
ReplyDeleteThanks
DeleteModuleNotFoundError Traceback (most recent call last)
ReplyDeletein ()
----> 1 from bidi.algorithm import get_display
2 from arabic_reshaper import ArabicReshaper
3
4 configuration = {
5 "language": "Urdu"
ModuleNotFoundError: No module named 'bidi'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Install this package
Deletehttps://pypi.org/project/python-bidi/
I am retrieving urdu text from mysql table. But it is displayed in bottom to top and i want it to be displayed from top to bottom, any solution will you suggest?
ReplyDeleteOr python reads the urdu text in backward direction while reading it from mysql table
ReplyDeleteDisplayed from bottom to top? What do you mean? Which os you are using? It mostly the issue of OS due to insufficient support for Urdu.
ReplyDelete