Skip to content

Fix issue with locale comma when not using math text #26804

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 1 commit into from
Sep 18, 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
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,11 @@ def _impl_locale_comma():
fmt = ',$\\mathdefault{,%1.1f},$'
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
assert x == ',$\\mathdefault{,0{,}5},$'
# Make sure no brackets are added if not using math text
ticks = mticker.ScalarFormatter(useMathText=False, useLocale=True)
fmt = '%1.1f'
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
assert x == '0,5'


def test_locale_comma():
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ def _format_maybe_minus_and_locale(self, fmt, arg):
Format *arg* with *fmt*, applying Unicode minus and locale if desired.
"""
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(","))
# Escape commas introduced by locale.format_string if using math text,
# but not those present from the beginning in fmt.
(",".join(locale.format_string(part, (arg,), True).replace(",", "{,}")
for part in fmt.split(",")) if self._useMathText
else locale.format_string(fmt, (arg,), True))
if self._useLocale
else fmt % arg)

Expand Down