Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arabic text in matplotlib [duplicate]

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()

enter image description here

like image 375
Ahmed007 Avatar asked May 26 '26 05:05

Ahmed007


1 Answers

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

like image 144
ALSHARGI NEWYORK Avatar answered May 30 '26 02:05

ALSHARGI NEWYORK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!