Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Fix issue with PGF backend not falling back to default LaTeX fonts.#22111
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,7 +4,9 @@ | ||
========= | ||
""" | ||
import matplotlib as mpl | ||
import matplotlib.pyplot as plt | ||
mpl.use("pgf") | ||
oscargus marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
plt.rcParams.update({ | ||
"font.family": "serif", | ||
# Use LaTeX default serif font. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -65,11 +65,18 @@ def _get_preamble(): | ||
families = ["serif", "sans\\-serif", "monospace"] | ||
commands = ["setmainfont", "setsansfont", "setmonofont"] | ||
for family, command in zip(families, commands): | ||
try: | ||
# 1) Forward slashes also work on Windows, so do not mess | ||
# with backslashes. | ||
# 2) The dirname needs to include a separator. | ||
path = pathlib.Path(fm.findfont(family, | ||
fallback_to_default=False)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. minor nit: only the findfont call should be wrapped in the try... except; this makes it clearer that you're catching failures of findfont and not e.g. findfont returning an invalid value for Path(). (Plus this avoids the awkward linebreak.) | ||
except ValueError: | ||
# Use default LaTeX font instead | ||
pass | ||
else: | ||
preamble.append(r"\%s{%s}[Path=\detokenize{%s}]" % ( | ||
command, path.name, path.parent.as_posix() + "/")) | ||
return "\n".join(preamble) | ||