There was an error while loading. Please reload this page.
2 parents 33e51a5 + 3d106ae commit cb21d7dCopy full SHA for cb21d7d
2 files changed
lib/matplotlib/_mathtext.py
@@ -519,6 +519,11 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
519
found_symbol = False
520
font = self._get_font(new_fontname)
521
if font is not None:
522
+ if font.family_name == "cmr10" and uniindex == 0x2212:
523
+ # minus sign exists in cmsy10 (not cmr10)
524
+ font = get_font(
525
+ cbook._get_data_path("fonts/ttf/cmsy10.ttf"))
526
+ uniindex = 0xa1
527
glyphindex = font.get_char_index(uniindex)
528
if glyphindex != 0:
529
found_symbol = True
lib/matplotlib/tests/test_mathtext.py
@@ -385,3 +385,15 @@ def test_math_fontfamily():
385
size=24, math_fontfamily='dejavusans')
386
fig.text(0.2, 0.3, r"$This\ text\ should\ have\ another$",
387
size=24, math_fontfamily='stix')
388
+
389
390
+def test_mathtext_cmr10_minus_sign():
391
+ # cmr10 does not contain a minus sign and used to issue a warning
392
+ # RuntimeWarning: Glyph 8722 missing from current font.
393
+ mpl.rcParams['font.family'] = 'cmr10'
394
+ mpl.rcParams['axes.formatter.use_mathtext'] = True
395
+ fig, ax = plt.subplots()
396
+ ax.plot(range(-1, 1), range(-1, 1))
397
+ with pytest.warns(None) as record:
398
+ fig.canvas.draw()
399
+ assert len(record) == 0, "\n".join(str(e.message) for e in record)
0 commit comments