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

Skip to content

Commit db5472b

Browse files
committed
Fix unintended space after comma as a decimal separator
1 parent 39070ae commit db5472b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,21 @@ def test_latex(self, is_latex, usetex, expected):
14491449
assert fmt.format_pct(50, 100) == expected
14501450

14511451

1452+
def test_locale_comma():
1453+
import locale
1454+
1455+
currentLocale = locale.getlocale()
1456+
try:
1457+
locale.setlocale(locale.LC_ALL, 'fy_DE.UTF-8')
1458+
except locale.Error as err:
1459+
pytest.fail("Locale 'fy_DE.UTF-8' is not supported")
1460+
ticks = mticker.ScalarFormatter(useMathText=True, useLocale=True)
1461+
fmt = '$\\mathdefault{%1.1f}$'
1462+
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1463+
locale.setlocale(locale.LC_ALL, currentLocale)
1464+
assert x == '$\\mathdefault{0{,}5}$'
1465+
1466+
14521467
def test_majformatter_type():
14531468
fig, ax = plt.subplots()
14541469
with pytest.raises(TypeError):

lib/matplotlib/ticker.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,14 @@ def _format_maybe_minus_and_locale(self, fmt, arg):
517517
"""
518518
Format *arg* with *fmt*, applying Unicode minus and locale if desired.
519519
"""
520-
return self.fix_minus(locale.format_string(fmt, (arg,), True)
521-
if self._useLocale else fmt % arg)
520+
return self.fix_minus(
521+
# Escape commas introduced by format_string but not those present
522+
# from the beginning in fmt.
523+
",".join(locale.format_string(part, (arg,), True)
524+
.replace(",", "{,}")
525+
for part in fmt.split(","))
526+
if self._useLocale
527+
else fmt % arg)
522528

523529
def get_useMathText(self):
524530
"""

0 commit comments

Comments
 (0)