xlabel and ylabel don't display Arabic
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]
plt.bar(x, y, label='Bar1', color='red')
plt.xlabel("الفواصل")
plt.ylabel("الترتيبات")
plt.show()
xlabel and ylabel don't display Arabic
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]
plt.bar(x, y, label='Bar1', color='red')
plt.xlabel("الفواصل")
plt.ylabel("الترتيبات")
plt.show()
You will first need to install both arabic-reshaper and python-bidi.
import arabic_reshaper
from bidi.algorithm import get_display
import matplotlib.pyplot as plt
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]
xlbl = get_display( arabic_reshaper.reshape('الفواصل'.decode('utf8')))
ylbl = get_display( arabic_reshaper.reshape('الترتيبات'.decode('utf8')))
plt.bar(x, y, label='Bar1', color='red')
plt.xlabel(xlbl, fontdict=None, labelpad=None)
plt.ylabel(ylbl, fontdict=None, labelpad=None)
plt.show()
plot Arabic
It should work if you use unicode strings (u"الفواصل"
) instead of usual strings.
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]
plt.bar(x, y, label='Bar1', color='red')
plt.xlabel(u"الفواصل")
plt.ylabel(u"الترتيبات")
plt.show()
Or, in order to get the correct order
import matplotlib.pyplot as plt
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]
plt.bar(x, y, label='Bar1', color='red')
plt.xlabel(u"الفواصل"[::-1])
plt.ylabel(u"الترتيبات"[::-1])
plt.show()