Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix cmr10 negative sign in cmsy10 (RuntimeWarning: Glyph 8722 missing) #18397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)