Created
May 20, 2020 05:25
-
-
Save farhadmpr/72840c961c261c74acdd1770c04a6298 to your computer and use it in GitHub Desktop.
Matplotlib with persian characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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