2015-10-06 50 views
4

我是一個法國的母語,所以我的操作系統接口(GNU/Linux的Xubuntu上)在法國英語作爲語言的日期蜱使用matplotlib

因此,當我繪製使用Matplotlib一個時間序列datetime爲X數據,返回的圖表用法語寫成月份

如何以另一種語言(通常是英語)獲取這些打印日期?

回答

3

您可以使用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' 
+0

I for必須提到我使用的是GNU/Linux(Xubuntu發行版),locale.setlocale(locale.LC_ALL,'fr_FR')'''生成錯誤'''locale.Error:不支持的語言環境設置' – Covich

2

使用湯姆的回答和the post hereafter,對於Ubuntu的像OS本地設置爲:

可用語言列表可以在bash中獲得 $ local -a