From 25051ba778cfff7af6978253852e80445977458b Mon Sep 17 00:00:00 2001 From: voidstarstar Date: Tue, 23 Apr 2024 22:41:39 -0400 Subject: [PATCH 1/2] Wrap the PercentFormatter result in \mathdefault --- lib/matplotlib/ticker.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) From 5c6a0c2fad83b0952b7559c6a013635b0e8481e4 Mon Sep 17 00:00:00 2001 From: voidstarstar Date: Thu, 2 May 2024 11:48:40 -0400 Subject: [PATCH 2/2] Update tests for the new PercentFormatter output --- lib/matplotlib/tests/test_ticker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(