Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: unintended space between comma and digit when using useMathText = True together with comma as decimal separator #23626

Copy link
Copy link
Closed
@der-zi

Description

@der-zi
Issue body actions

Bug summary

When I turn on "useMathText" in matplotlib in the intention to replace 1e6 by $\times 10^6$, the formatting of the commas in the tick labels themselves get wrong. Before they are correct in the form "3,5", with "useMathText" they become "3, 5", with (half?) a whitespace between the comma and the following digit.
correct_but_ugly_dec_power
incorrect

Code for reproduction

%matplotlib inline
import locale
locale.setlocale(locale.LC_ALL, "deu_deu")
import matplotlib.pyplot as plt

plt.rcParams['axes.formatter.use_locale'] = True

fig, ax = plt.subplots()
x = [1000, 2000, 3000, 3.5e6]
y = [1, 4, 3, 5]
ax.plot(x, y, linestyle = "", marker = "o")
ax.set_xlabel("the x-axis")
ax.ticklabel_format(axis = 'x', useMathText = True)

Actual outcome

the formatting of the decimal power is altered, but the ticklabels themselves are rendered incorrectly (additional space between comma and following digit)

Expected outcome

the formatting of the decimal power is altered, and the ticklabels themselves are rendered correctly (as before adding useMathText = True)

Additional information

apparently, matplotlib uses LaTeX to render the mathematical notation of power, and also changes the way the normal ticklabels are created to TeX mode.
however, when using comma as decimal separator in TeX you have to consider that it is written by americans, using the comma as an element separator, not decimal separator, and therefore in standard configuration automatically adds a space behind the comma.

this can be fixed by using
3{,}5
or
3,\!5
or
\num{3,5} or \num{3.5} with siunitx configured correctly
or with the package icomma.

(Also, when already using the locale set to german, one could be expecting \cdot rather than \times. There should be an option to choose between these)

Operating system

No response

Matplotlib Version

3.5.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.9.7

Jupyter version

6.4.10

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!topic: text/mathtext

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.