Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix unintended space after comma as a decimal separator #25226

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

Merged
merged 6 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,24 @@ def test_latex(self, is_latex, usetex, expected):
assert fmt.format_pct(50, 100) == expected


def test_locale_comma():
currentLocale = locale.getlocale()
try:
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
ticks = mticker.ScalarFormatter(useMathText=True, useLocale=True)
fmt = '$\\mathdefault{%1.1f}$'
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
assert x == '$\\mathdefault{0{,}5}$'
# Do not change , in the format string
fmt = ',$\\mathdefault{,%1.1f},$'
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
assert x == ',$\\mathdefault{,0{,}5},$'
except locale.Error:
pytest.skip("Locale de_DE.UTF-8 is not supported on this machine")
finally:
locale.setlocale(locale.LC_ALL, currentLocale)


def test_majformatter_type():
fig, ax = plt.subplots()
with pytest.raises(TypeError):
Expand Down
10 changes: 8 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,14 @@ def _format_maybe_minus_and_locale(self, fmt, arg):
"""
Format *arg* with *fmt*, applying Unicode minus and locale if desired.
"""
return self.fix_minus(locale.format_string(fmt, (arg,), True)
if self._useLocale else fmt % arg)
return self.fix_minus(
# Escape commas introduced by format_string but not those present
# from the beginning in fmt.
",".join(locale.format_string(part, (arg,), True)
.replace(",", "{,}")
for part in fmt.split(","))
if self._useLocale
else fmt % arg)

def get_useMathText(self):
"""
Expand Down