Skip to content

[ENH]: Please add full locale-support to all visualizable matplotlib-elements (title, lables, ticks, text, etc...) #30601

@Dephrilibrium

Description

@Dephrilibrium

Problem

Hello Dev-Team of Matplotlib,

Currently I have to prepare a lot of plots which were originally made in english. Now they have to be translated to german which means the decimal- and thousands-separator has to be replaced.
I looked for an option to globally set the locale as it is handled in other languages (C# for instance).
Just as an example, I tried to set the locale "de_DE.UTF-8" with the locale-package and told the matplotlib axis-formatter with rcparams to "use_locale=True". However, that didn't worked for the "text"-elements which are inserted into the plot.
Here is the example I've tested:

import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# Set locale globally
import locale
locale.setlocale(locale.LC_NUMERIC, "de_DE.UTF-8")
# Set "use_locale" to formatter
plt.rcdefaults()
plt.rcParams['axes.formatter.use_locale'] = True # tell matplotlib to use the set de_DE locale!
print('matplotlib: {}'.format(matplotlib.__version__))

x = [1, 1.1, 1.3, 1.5, 2]
y = [4.0, 4.2, 4.5, 4.8, 5.0]
fig, ax = plt.subplots(figsize=(16,15), nrows=1, ncols=1)
ax.plot(x, y)
ax.text(x=1.5,y=4.5,s=f"{1.23:.2f}") # The text still appears with "1.23" instead of "1,23"

plt.show(block=False)

Therefore I wanted to request this enhancement to implement the global locale-support for all other printable/plotable matplotlib-elements which are able to convert numbers in visualized strings.

Version:
OS: Windows 11 24H2
Python: 3.12.8
Matplotlib: 3.10.6

Best regards,
Deph

PS: I searched in issues for "separator" and "locale"

Proposed solution

Add some kind of additional formatter for other elements like "text.formatter" to set them "use_locale" too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions