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

Skip to content

Commit 09c5cb3

Browse files
committed
Do not add default matplotlib font, but rely on the default LaTeX font.
1 parent 89331ee commit 09c5cb3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

examples/userdemo/pgf_fonts.py

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

7+
import matplotlib as mpl
78
import matplotlib.pyplot as plt
9+
mpl.use("pgf")
810
plt.rcParams.update({
911
"font.family": "serif",
1012
# Use LaTeX default serif font.

lib/matplotlib/backends/backend_pgf.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,18 @@ def _get_preamble():
6565
families = ["serif", "sans\\-serif", "monospace"]
6666
commands = ["setmainfont", "setsansfont", "setmonofont"]
6767
for family, command in zip(families, commands):
68-
# 1) Forward slashes also work on Windows, so don't mess with
69-
# backslashes. 2) The dirname needs to include a separator.
70-
path = pathlib.Path(fm.findfont(family))
71-
preamble.append(r"\%s{%s}[Path=\detokenize{%s/}]" % (
72-
command, path.name, path.parent.as_posix()))
68+
try:
69+
# 1) Forward slashes also work on Windows, so do not mess
70+
# with backslashes.
71+
# 2) The dirname needs to include a separator.
72+
path = pathlib.Path(fm.findfont(family,
73+
fallback_to_default=False))
74+
except ValueError:
75+
# Use default LaTeX font instead
76+
pass
77+
else:
78+
preamble.append(r"\%s{%s}[Path=\detokenize{%s}]" % (
79+
command, path.name, path.parent.as_posix() + "/"))
7380
return "\n".join(preamble)
7481

7582

0 commit comments

Comments
 (0)