Persian Text in Matplolib
from bidi.algorithm import get_display import arabic_reshaper
def make_farsi_text(x): reshaped_text = arabic_reshaper.reshape(x) farsi_text = get_display(reshaped_text) return farsi_text
xlabel = "یک محور همینجوری" ylabel = "یک محور دیگه همینجوری" title = "یک نمودار همینجوری" plt.scatter(X[:,0],X[:,1],c = y, cmap = 'spring') plt.xlabel(make_farsi_text(xlabel),fontsize = 15) plt.ylabel(make_farsi_text(ylabel),fontsize = 15) plt.title(make_farsi_text(title) , fontsize = 20) plt.show()
font_title = {'family': 'B Farnaz',
'color': 'red',
'weight': 'normal',
'size': 30,
}
font_labels = {'family': 'B Nazanin',
'color': 'black',
'weight': 'normal',
'size': 20,
}
plt.scatter(X[:,0],X[:,1],c = y, cmap = 'spring')
plt.xlabel(make_farsi_text(xlabel),fontdict = font_labels)
plt.ylabel(make_farsi_text(ylabel),fontdict = font_labels)
plt.title(make_farsi_text(title) ,fontdict = font_title)
plt.show()
References
http://imuhammad.ir/2017/09/23/farsi-plots-python/
https://pypi.org/project/python-bidi/
https://github.com/mpcabd/python-arabic-reshaper