From 71ea0cdce8dbb0d73be45e92e8d0ec04ad566ff4 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 2 Sep 2020 20:55:56 +0100 Subject: [PATCH 1/7] fix cmr10 negative sign in cmsy10 - fixes #17007 - see https://github.com/matplotlib/matplotlib/issues/17007#issuecomment-685951519 --- lib/matplotlib/_mathtext.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 62382f20a789..0e30ebd1861d 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -519,6 +519,11 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True): found_symbol = False font = self._get_font(new_fontname) if font is not None: + if font.family_name == "cmr10" and uniindex == 0x2212: + # minus sign exists in cmsy10 (not cmr10) + font = get_font( + cbook._get_data_path("fonts/ttf/cmsy10.ttf")) + uniindex = 0xa1 glyphindex = font.get_char_index(uniindex) if glyphindex != 0: found_symbol = True From 6f362d6b4facf70aab40bbf42bd35dbcfde06af7 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 10 Nov 2020 15:57:22 +0000 Subject: [PATCH 2/7] add test --- lib/matplotlib/tests/test_mathtext.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 5236e1299809..573083513475 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -385,3 +385,8 @@ def test_math_fontfamily(): size=24, math_fontfamily='dejavusans') fig.text(0.2, 0.3, r"$This\ text\ should\ have\ another$", size=24, math_fontfamily='stix') + + +def test_mathtext_fontfamily(): + fig = plt.figure(figsize=(10, 3)) + fig.text(.5, .5, '$a-b$', fontsize=40, ha='center', math_fontfamily='cmr10') From 0503854c97676fc10b7246a19bfc865432f55d97 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 10 Nov 2020 17:46:32 +0000 Subject: [PATCH 3/7] fix cmr10 test --- lib/matplotlib/tests/test_mathtext.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 573083513475..134957cce7ef 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -388,5 +388,6 @@ def test_math_fontfamily(): def test_mathtext_fontfamily(): - fig = plt.figure(figsize=(10, 3)) - fig.text(.5, .5, '$a-b$', fontsize=40, ha='center', math_fontfamily='cmr10') + mpl.rcParams['font.family'] = 'cmr10' + fig, ax = plt.subplots() + ax.plot(range(-1, 1), range(-1, 1)) From d4d701ad1220c0578e46690aa7e2541e735dc759 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 17 Nov 2020 12:48:43 +0000 Subject: [PATCH 4/7] Update cmr10 minus sign test Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/tests/test_mathtext.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 134957cce7ef..56f8d18d4219 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -387,7 +387,12 @@ def test_math_fontfamily(): size=24, math_fontfamily='stix') -def test_mathtext_fontfamily(): +def test_mathtext_cmr10_minus_sign(): + # cmr10 does not contain a minus sign and used to issue a warning + # RuntimeWarning: Glyph 8722 missing from current font. mpl.rcParams['font.family'] = 'cmr10' fig, ax = plt.subplots() ax.plot(range(-1, 1), range(-1, 1)) + with pytest.warns(None) as record: + fig.canvas.draw() + assert len(record) == 0 From 5092a8d8161e8330f5fd86a8f18513f4ffbd2d7b Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 17 Nov 2020 12:51:54 +0000 Subject: [PATCH 5/7] fix whitespace --- lib/matplotlib/tests/test_mathtext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 56f8d18d4219..a1755f36bbef 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -395,4 +395,4 @@ def test_mathtext_cmr10_minus_sign(): ax.plot(range(-1, 1), range(-1, 1)) with pytest.warns(None) as record: fig.canvas.draw() - assert len(record) == 0 + assert len(record) == 0 From ff0cf3ad5d0d4dea91712794f34d1d577b2ea2da Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 18 Nov 2020 00:20:36 +0000 Subject: [PATCH 6/7] debug --- lib/matplotlib/tests/test_mathtext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index a1755f36bbef..064a7c437f23 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -395,4 +395,4 @@ def test_mathtext_cmr10_minus_sign(): ax.plot(range(-1, 1), range(-1, 1)) with pytest.warns(None) as record: fig.canvas.draw() - assert len(record) == 0 + assert len(record) == 0, "\n".join(str(e.message) for e in record) From 3d106ae7e3c594cca0b1efeca179e2d21e8497c8 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 24 Apr 2021 15:22:36 +0100 Subject: [PATCH 7/7] fix test config Co-authored by: Aitik Gupta --- lib/matplotlib/tests/test_mathtext.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 064a7c437f23..24cfaa95122a 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -391,6 +391,7 @@ def test_mathtext_cmr10_minus_sign(): # cmr10 does not contain a minus sign and used to issue a warning # RuntimeWarning: Glyph 8722 missing from current font. mpl.rcParams['font.family'] = 'cmr10' + mpl.rcParams['axes.formatter.use_mathtext'] = True fig, ax = plt.subplots() ax.plot(range(-1, 1), range(-1, 1)) with pytest.warns(None) as record: