Skip to content

Commit f923a8a

Browse files
committed
Fix issue with locale comma when not using math text
1 parent 9b16729 commit f923a8a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/matplotlib/tests/test_ticker.py

+5
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,11 @@ def _impl_locale_comma():
16541654
fmt = ',$\\mathdefault{,%1.1f},$'
16551655
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
16561656
assert x == ',$\\mathdefault{,0{,}5},$'
1657+
# Make sure no brackets are added if not using math text
1658+
ticks = mticker.ScalarFormatter(useMathText=False, useLocale=True)
1659+
fmt = '%1.1f'
1660+
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1661+
assert x == '0,5'
16571662

16581663

16591664
def test_locale_comma():

lib/matplotlib/ticker.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,11 @@ def _format_maybe_minus_and_locale(self, fmt, arg):
516516
Format *arg* with *fmt*, applying Unicode minus and locale if desired.
517517
"""
518518
return self.fix_minus(
519-
# Escape commas introduced by format_string but not those present
520-
# from the beginning in fmt.
521-
",".join(locale.format_string(part, (arg,), True)
522-
.replace(",", "{,}")
523-
for part in fmt.split(","))
519+
# Escape commas introduced by locale.format_string if using math text,
520+
# but not those present from the beginning in fmt.
521+
(",".join(locale.format_string(part, (arg,), True).replace(",", "{,}")
522+
for part in fmt.split(",")) if self._useMathText
523+
else locale.format_string(fmt, (arg,), True))
524524
if self._useLocale
525525
else fmt % arg)
526526

0 commit comments

Comments
 (0)