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 diff --git a/lib/matplotlib/tests/test_mathtext.py b/lib/matplotlib/tests/test_mathtext.py index 5236e1299809..24cfaa95122a 100644 --- a/lib/matplotlib/tests/test_mathtext.py +++ b/lib/matplotlib/tests/test_mathtext.py @@ -385,3 +385,15 @@ 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_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: + fig.canvas.draw() + assert len(record) == 0, "\n".join(str(e.message) for e in record) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy