Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 31e5682

Browse filesBrowse files
authored
Merge pull request #25226 from devRD/tickertex
Fix unintended space after comma as a decimal separator
2 parents 070477c + 8c826b9 commit 31e5682
Copy full SHA for 31e5682

File tree

Expand file treeCollapse file tree

2 files changed

+26
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-2
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,24 @@ def test_latex(self, is_latex, usetex, expected):
14491449
assert fmt.format_pct(50, 100) == expected
14501450

14511451

1452+
def test_locale_comma():
1453+
currentLocale = locale.getlocale()
1454+
try:
1455+
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
1456+
ticks = mticker.ScalarFormatter(useMathText=True, useLocale=True)
1457+
fmt = '$\\mathdefault{%1.1f}$'
1458+
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1459+
assert x == '$\\mathdefault{0{,}5}$'
1460+
# Do not change , in the format string
1461+
fmt = ',$\\mathdefault{,%1.1f},$'
1462+
x = ticks._format_maybe_minus_and_locale(fmt, 0.5)
1463+
assert x == ',$\\mathdefault{,0{,}5},$'
1464+
except locale.Error:
1465+
pytest.skip("Locale de_DE.UTF-8 is not supported on this machine")
1466+
finally:
1467+
locale.setlocale(locale.LC_ALL, currentLocale)
1468+
1469+
14521470
def test_majformatter_type():
14531471
fig, ax = plt.subplots()
14541472
with pytest.raises(TypeError):

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,14 @@ def _format_maybe_minus_and_locale(self, fmt, arg):
510510
"""
511511
Format *arg* with *fmt*, applying Unicode minus and locale if desired.
512512
"""
513-
return self.fix_minus(locale.format_string(fmt, (arg,), True)
514-
if self._useLocale else fmt % arg)
513+
return self.fix_minus(
514+
# Escape commas introduced by format_string but not those present
515+
# from the beginning in fmt.
516+
",".join(locale.format_string(part, (arg,), True)
517+
.replace(",", "{,}")
518+
for part in fmt.split(","))
519+
if self._useLocale
520+
else fmt % arg)
515521

516522
def get_useMathText(self):
517523
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.