Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

English as language for the dates ticks using matplotlib

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) ?

like image 525
Covich Avatar asked Oct 06 '15 16:10

Covich


People also ask

How do I change the date format in Matplotlib?

Using the DateFormatter module from matplotlib, you can specify the format that you want to use for the date using the syntax: "%X %X" where each %X element represents a part of the date as follows: %Y - 4 digit year with upper case Y. %y - 2 digit year with lower case y. %m - month as a number with lower case m.

What is the use of Ticks in Matplotlib?

Ticks are the values used to show specific points on the coordinate axis. It can be a number or a string. Whenever we plot a graph, the axes adjust and take the default ticks. Matplotlib's default ticks are generally sufficient in common situations but are in no way optimal for every plot.

What is Xticks and Yticks in Matplotlib?

MatPlotLib with Python Position and labels of ticks can be explicitly mentioned to suit specific requirements. The xticks() and yticks() function takes a list object as argument. The elements in the list denote the positions on corresponding action where ticks will be displayed.


2 Answers

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'
like image 183
tmdavison Avatar answered Oct 19 '22 04:10

tmdavison


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

like image 42
Covich Avatar answered Oct 19 '22 02:10

Covich