Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
oscargus wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromoscargus:pgffonts
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionsexamples/userdemo/pgf_fonts.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,9 @@
=========
"""

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use("pgf")
plt.rcParams.update({
"font.family": "serif",
# Use LaTeX default serif font.
Expand Down
17 changes: 12 additions & 5 deletionslib/matplotlib/backends/backend_pgf.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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
Contributor

Choose a reason for hiding this comment

The 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)


Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp