Skip to content

Commit

Permalink
Merge pull request matplotlib#26809 from meeseeksmachine/auto-backpor…
Browse files Browse the repository at this point in the history
…t-of-pr-26804-on-v3.8.x

Backport PR matplotlib#26804 on branch v3.8.x (Fix issue with locale comma when not using math text)
  • Loading branch information
oscargus authored Sep 18, 2023
2 parents 406a5ea + 15d6c2f commit 0729415
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit 0729415

Please sign in to comment.