Is there a way to show Persian date in x-axis of Matplotlib plot

天涯浪子 提交于 2020-08-20 03:56:26

问题


I want to plot a dataframe in which the index consists of datetime values based on Iranian calendar.

I want to set the x-axis labels as following:

import matplotlib.dates as mdates

axes.scatter(df_day.index.values, df_day.loc[:, item], marker='.')
axes.xaxis.set_major_formatter(dates.DateFormatter('%d-%b %H:%M'))

Consider that I want to print the months's name in Persian instead of default value of Georgian calendar such as Jun or Aug.

I used jdatetime to convert the datetime in persian calendar but the plot function doesn't take it's value as x-axis index. then I used jalaali to create a datetime based on persian calendar that plot accepts it.

now the problem is how to print x-axis label as Persian month names? because I want this format:

dates.DateFormatter('%d-%b %H:%M')

Is there any way of doing that?

UPDATE

I used locale to access to the POSIX locale database and functionality as following:

import locale 

locale.setlocale(locale.LC_ALL, 'fa_IR')

but it only changed the name of Georgian months from English alphabet in Persian alphabet instead of showing jalali names such as فروردین or اردیبهشت.

any clue is appreciated.

来源:https://stackoverflow.com/questions/63356748/is-there-a-way-to-show-persian-date-in-x-axis-of-matplotlib-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!