diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index e91d3236020d..66da7081b074 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -1352,6 +1352,17 @@ def test_engformatter_usetex_useMathText(): assert x_tick_label_text == ['$0$', '$500$', '$1$ k'] +def test_locale_comma(): + import locale + currentLocale = locale.getlocale() + locale.setlocale(locale.LC_ALL, 'deu_deu') + ticks = mticker.ScalarFormatter(useMathText=True, useLocale=True) + fmt = '$\\mathdefault{%1.1f}$' + formatted = ticks._format_maybe_minus_and_locale(fmt, 0.5) + locale.setlocale(locale.LC_ALL, currentLocale) + assert formatted == '$\\mathdefault{0{,}5}$' + + class TestPercentFormatter: percent_data = [ # Check explicitly set decimals over different intervals and values diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index dfacdf4aead9..dac139469c52 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -532,8 +532,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(locale.format_string(fmt, (arg,), True) - if self._useLocale else fmt % arg) + formatted = self.fix_minus(locale.format_string(fmt, (arg,), True) + if self._useLocale else fmt % arg) + if (self.get_useMathText()): # removed unintended space after comma + formatted = formatted.replace(',', '{,}') + return formatted def get_useMathText(self): """