diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 36b83c95b3d3..46c26c59b525 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -1634,9 +1634,9 @@ class TestPercentFormatter: latex_data = [ (False, False, r'50\{t}%'), - (False, True, r'50\\\{t\}\%'), + (False, True, r'$\mathdefault{50\\\{t\}\%}$'), (True, False, r'50\{t}%'), - (True, True, r'50\{t}%'), + (True, True, r'$\mathdefault{50\{t}%}$'), ] @pytest.mark.parametrize( diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index f042372a7be9..1dcdc37e2fb0 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1556,8 +1556,11 @@ def format_pct(self, x, display_range): else: decimals = self.decimals s = f'{x:0.{int(decimals)}f}' + s += self.symbol + if mpl.rcParams['text.usetex']: + s = r'$\mathdefault{%s}$' % s - return s + self.symbol + return s def convert_to_pct(self, x): return 100.0 * (x / self.xmax)