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

Skip to content

Commit 7423718

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

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ 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+
latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % (
57+
command, path.name, path.parent.as_posix() + "/"))
58+
except ValueError:
59+
# Use default LaTeX font instead
60+
pass
5761
return "\n".join(latex_fontspec)
5862

5963

0 commit comments

Comments
 (0)