2

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.

4

1 回答 1

0

你可以使用plotly而不是matplotlib这里是一个简单的例子:

import datetime
import plotly.express as px

base = datetime.datetime.today()
date_list = [base + datetime.timedelta(days=x) for x in range(200)]
nums = list(range(200))

fig = px.line(x=date_list, y=nums)
fig.update_xaxes(calendar='jalali')
fig.show()

输出如下图: 在此处输入图像描述

于 2021-09-11T10:34:06.553 回答