Skip to content

Instantly share code, notes, and snippets.

@farhadmpr
Created May 20, 2020 05:25
Show Gist options
  • Save farhadmpr/72840c961c261c74acdd1770c04a6298 to your computer and use it in GitHub Desktop.
Save farhadmpr/72840c961c261c74acdd1770c04a6298 to your computer and use it in GitHub Desktop.
Matplotlib with persian characters
import matplotlib.pyplot as plt
import pandas as pd
import arabic_reshaper
from matplotlib.pyplot import *
from bidi.algorithm import get_display
class Enums:
Year = 'سال'
Number = 'تعداد تخلفات'
def _(text):
return get_display(
arabic_reshaper.reshape(u'%s'%str(text))
)
df = pd.DataFrame(
{
Enums.Year:['۱۳۹۷', '۱۳۹۸', '۱۳۹۹'],
Enums.Number: [20, 30, 10]
}
)
fig, ax = subplots()
df.plot.bar(x=Enums.Year, y=Enums.Number, ax=ax)
ax.legend([_("تعداد")])
plt.xlabel(_(Enums.Year))
plt.ylabel(_(Enums.Number))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment