From 2f80fb86dbc33eda3b69b3b23d53aa971f832cce Mon Sep 17 00:00:00 2001 From: Franz Forstmayr Date: Mon, 30 Aug 2021 10:50:55 +0200 Subject: [PATCH] Fix #20850 Do not remove serif font family in pgf example to avoid Warning Add requested changes Revert "Fix #20850" This reverts commit 0bff071e4f41e19b74a2b51bf9c0a0dae02d2fff. --- lib/matplotlib/backends/backend_pgf.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 3f1cb7b172eb..e74985b7ae76 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -50,9 +50,14 @@ def get_fontspec(): 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)) - latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % ( - command, path.name, path.parent.as_posix() + "/")) + try: + path = pathlib.Path( + fm.findfont(family, fallback_to_default=False)) + except ValueError: + pass + else: + latex_fontspec.append(r"\%s{%s}[Path=\detokenize{%s}]" % ( + command, path.name, path.parent.as_posix() + "/")) return "\n".join(latex_fontspec)