-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: unintended space between comma and digit when using useMathText = True together with comma as decimal separator #23626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is probably the place to fix it: matplotlib/lib/matplotlib/ticker.py Lines 531 to 536 in d3038bf
The main issue is most likely how to deal with format strings that already includes a |
For |
A possibility is perhaps to just copypaste the logic of python's format_string (https://github.com/python/cpython/blob/f7e7bf161aaec5a5cffdcec7c97e1f09e445421b/Lib/locale.py#L213), split out format specifiers and non-specifiers and brace-escape the non-specifiers. |
Marking as a good first issue, but medium, as it is well defined what should happen, but maybe not so straightforward to solve. |
Currently working on this issue. |
I have a quick fix PR ready to submit that changes the "," to "{,}" under the given conditions. I'm unsure how I would implement a pytest for this change. Is it necessary because it is a small and mostly visual change and if so does anyone have advice on what to assert? |
It is set with matplotlib/lib/matplotlib/backend_bases.py Lines 3044 to 3072 in a283d20
|
For the testing, it probably makes sense to have a parameterized test for a few locales (one using @pytest.mark.parametrize("loc, result", (('DE', (r'3,5 \times 10^3', ...))
def test_locale_comma(loc, result):
locale.setlocale(locale.LC_ALL, loc)
...
assert ... == result Maybe even create a formatter that uses a |
Is anyone working on this issue? I would like to work on this issue following the discussion here and the discussion from #24079 |
Uh oh!
There was an error while loading. Please reload this page.
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.


Code for reproduction
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
The text was updated successfully, but these errors were encountered: