Repository navigation
Closed
Labels
Description
I have an issue where I set the locale of the python script with locale.setlocale(). When I then create a figure, the locale is reset to the default.
I have trouble pinning it down exactly. On my computer (OpenSuse Tumbleweed) it happens with Matplotlib from Git, but not with system-supplied matplotlib. On a CentOS 6 running Miniconda python, it happens with Matplotlib 1.5.1 supplied with Miniconda.
MWE:
from __future__ import print_function
import locale
import sys
print ('Python version:', sys.__version__)
print ("Initial locale:", locale.getlocale())
print ('Changing locale to en_US')
locale.setlocale(locale.LC_ALL, 'en_US.utf8')
print ("New locale:", locale.getlocale())
import matplotlib
print ("Matplotlib version:", matplotlib.__version__)
print ("Locale after importing matplotlib:", locale.getlocale())
import matplotlib.pyplot as pyplot
print ("Locale after importing pyplot:", locale.getlocale())
pyplot.figure()
print ("Locale after creating figure:", locale.getlocale())Running the MWE on my computer:
§~/src> python3 mwe.py
Python version: 3.5.1 (default, Dec 09 2015, 07:29:36) [GCC]
Initial locale: ('nn_NO', 'UTF-8')
Changing locale to en_US
New locale: ('en_US', 'UTF-8')
Matplotlib version: 2.0.0b1+1771.g5dfe000
Locale after importing matplotlib: ('en_US', 'UTF-8')
Locale after importing pyplot: ('en_US', 'UTF-8')
Locale after creating figure: ('nn_NO', 'UTF-8')
§~/src> mv ~/.local/lib/python3.5/ ~/.local/lib/xpython3.5/ # Revert to system-supplied matplotlib
§~/src> python3 mwe.py
Python version: 3.5.1 (default, Dec 09 2015, 07:29:36) [GCC]
Initial locale: ('nn_NO', 'UTF-8')
Changing locale to en_US
New locale: ('en_US', 'UTF-8')
Matplotlib version: 1.5.1
Locale after importing matplotlib: ('en_US', 'UTF-8')
Locale after importing pyplot: ('en_US', 'UTF-8')
Locale after creating figure: ('en_US', 'UTF-8')
To help us understand and resolve your issue please check that you have provided
the information below.
- Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
- How did you install Matplotlib and Python (pip, anaconda, from source ...)
- If possible please supply a Short, Self Contained, Correct, Example
that demonstrates the issue i.e a small piece of code which reproduces the issue
and can be run with out any other (or as few as possible) external dependencies. - If this is an image generation bug attach a screenshot demonstrating the issue.
- If this is a regression (Used to work in an earlier version of Matplotlib), please
note where it used to work.
Activity
anntzer commentedon Jul 9, 2016
A quick look indicates that the behavior is backend dependent. Non-interactive backends do not reset the locale. Qt5Agg resets it after importing
figure; TkAgg resets it after importingpyplot.tacaswell commentedon Jul 10, 2016
If it is backend dependent that I suspect it is the default locale handling in the GUI frameworks.
anntzer commentedon Dec 2, 2016
I can confirm that this is due to locale handling by the GUI framework.
tkinterappears to reset the locale when imported for the first time:Likewise Qt5 resets the locale when the QApplication is created.
Thus the best thing that can be done is probably to add a note in the docs to that effect.
anntzer commentedon Dec 29, 2018
I'm going to close this as far too specific to be worth an entry in the docs IMO.
Still, thanks for the report.