Skip to content

Commit 35a5189

Browse files
committed
Do not add default matplotlib font, but rely on the default LaTeX font.
1 parent 68d6b79 commit 35a5189

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎examples/userdemo/pgf_fonts.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
66
"""
77

8+
import matplotlib as mpl
89
import matplotlib.pyplot as plt
10+
mpl.use("pgf")
911
plt.rcParams.update({
1012
"font.family": "serif",
1113
# Use LaTeX default serif font.

‎lib/matplotlib/backends/backend_pgf.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ def get_fontspec():
4848
families = ["serif", "sans\\-serif", "monospace"]
4949
commands = ["setmainfont", "setsansfont", "setmonofont"]
5050
for family, command in zip(families, commands):
51-
# 1) Forward slashes also work on Windows, so don't mess with
52-
# backslashes. 2) The dirname needs to include a separator.
53-
path = pathlib.Path(fm.findfont(family))
54-
latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % (
55-
command, path.name, path.parent.as_posix() + "/"))
56-
51+
try:
52+
# 1) Forward slashes also work on Windows, so don't mess with
53+
# backslashes. 2) The dirname needs to include a separator.
54+
path = pathlib.Path(fm.findfont(family,
55+
fallback_to_default=False))
56+
except ValueError:
57+
# Use default LaTeX font instead
58+
pass
59+
else:
60+
latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % (
61+
command, path.name, path.parent.as_posix() + "/"))
5762
return "\n".join(latex_fontspec)
5863

5964

0 commit comments

Comments
 (0)