【发布时间】:2016-01-03 15:31:12
【问题描述】:
我的母语是法语,所以我的操作系统界面(GNU/Linux Xubuntu)是法语的
因此,当我使用 Matplotlib 以 datetime 作为 X 数据绘制时间序列时,返回的图具有用法语编写的月份
我怎样才能获得其他语言(通常是英语)的打印日期?
【问题讨论】:
标签: datetime matplotlib non-english
我的母语是法语,所以我的操作系统界面(GNU/Linux Xubuntu)是法语的
因此,当我使用 Matplotlib 以 datetime 作为 X 数据绘制时间序列时,返回的图具有用法语编写的月份
我怎样才能获得其他语言(通常是英语)的打印日期?
【问题讨论】:
标签: datetime matplotlib non-english
您可以使用locale 模块设置所需的位置/语言。要获得英语,请尝试将locale 设置为en_US。
编辑:
在 Ubuntu 上的 bash 中,您可能需要使用 en_US.utf8
In [1]: import datetime
In [2]: import locale
In [3]: locale.setlocale(locale.LC_ALL,'fr_FR')
Out[3]: 'fr_FR'
In [4]: datetime.datetime(2015,7,1).strftime('%B')
Out[4]: 'juillet'
In [5]: locale.setlocale(locale.LC_ALL,'en_US')
Out[5]: 'en_US'
In [6]: datetime.datetime(2015,7,1).strftime('%B')
Out[6]: 'July'
【讨论】:
locale.setlocale(locale.LC_ALL,'fr_FR') 生成错误locale.Error: unsupported locale setting
使用汤姆的回答和the post hereafter,类似 Ubuntu 的操作系统的本地设置是:
import locale
locale.setlocale(locale.LC_ALL,'en_US.utf8')
可用语言列表可以在终端中获取
$ locale -a
【讨论】: