English as language for the dates ticks using matplotlib

最后都变了- 提交于 2020-01-03 08:58:11

问题


I'm a French native speaker, so my OS interface (GNU/Linux Xubuntu) is in French

Thus, when I plot a time series using Matplotlib with datetime as X data, the returned plot have the months written in French

How can I obtain those printed dates in another language (typically English) ?


回答1:


You can set the desired location/language using the locale module. To get English, try setting locale to en_US.

EDIT: In bash on Ubuntu, you may need to use 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'



回答2:


Using tom's answer and the post hereafter, the local settings for an Ubuntu-like OS are : import locale locale.setlocale(locale.LC_ALL,'en_US.utf8')

The list of available languages can be obtained in the terminal with $ locale -a



来源:https://stackoverflow.com/questions/32974640/english-as-language-for-the-dates-ticks-using-matplotlib

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