FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix issue with PGF backend not falling back to default LaTeX fonts. by oscargus · Pull Request #22111 · matplotlib/matplotlib · GitHub

Repository navigation

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions examples/userdemo/pgf_fonts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
=========
"""

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use("pgf")
Comment thread
oscargus marked this conversation as resolved.
plt.rcParams.update({
"font.family": "serif",
# Use LaTeX default serif font.
Expand Down
17 changes: 12 additions & 5 deletions lib/matplotlib/backends/backend_pgf.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ def _get_preamble():
families = ["serif", "sans\\-serif", "monospace"]
commands = ["setmainfont", "setsansfont", "setmonofont"]
for family, command in zip(families, commands):
# 1) Forward slashes also work on Windows, so don't mess with
# backslashes. 2) The dirname needs to include a separator.
path = pathlib.Path(fm.findfont(family))
preamble.append(r"\%s{%s}[Path=\detokenize{%s/}]" % (
command, path.name, path.parent.as_posix()))
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)


Expand Down

Back | FazBrowse Home | New Git URL