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

Skip to content

Commit 7d280f9

Browse files
authored
Merge pull request #18825 from anntzer/pgffontwarn
Warn in pgf backend when unknown font is requested.
2 parents 2b055a0 + 79af49f commit 7d280f9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _font_properties_str(prop):
134134
and mpl.rcParams["pgf.texsystem"] != "pdflatex"):
135135
commands.append(r"\setmainfont{%s}\rmfamily" % family)
136136
else:
137-
pass # print warning?
137+
_log.warning("Ignoring unknown font: %s", family)
138138

139139
size = prop.get_size_in_points()
140140
commands.append(r"\fontsize{%f}{%f}" % (size, size * 1.2))

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,13 @@ def test_png():
328328
# Just a smoketest.
329329
fig, ax = plt.subplots()
330330
fig.savefig(BytesIO(), format="png", backend="pgf")
331+
332+
333+
@needs_xelatex
334+
def test_unknown_font(caplog):
335+
with caplog.at_level("WARNING"):
336+
mpl.rcParams["font.family"] = "this-font-does-not-exist"
337+
plt.figtext(.5, .5, "hello, world")
338+
plt.savefig(BytesIO(), format="pgf")
339+
assert "Ignoring unknown font: this-font-does-not-exist" in [
340+
r.getMessage() for r in caplog.records]

0 commit comments

Comments
 (0)