Repository navigation
Silence matplotlib 3.11's font-weight fallback warning in the i18n font cells - #111
Conversation
…nt cells matplotlib 3.11 (anaconda 2026.07) logs "findfont: Failed to find font weight normal, now using 600." whenever it falls back to the only weight of Source Han Serif SC we ship (SemiBold). 3.10 made the same fallback silently. The message goes to stderr, which the pages render, so 17 lectures showed it 77 times. Set the matplotlib.font_manager logger to ERROR next to the existing font registration in the 18 lectures that call fontManager.addfont. The figures are unchanged: the fallback still picks the SemiBold face, and a PNG drawn with and without the warning is byte-identical. Missing glyphs are still reported through the warnings module. Refs #110 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb
There was a problem hiding this comment.
🟢 Approval recommended
The change is a mechanical, consistent, and correct logger-level adjustment applied to all 18 lectures that register the font, with no missed files or logic issues.
0 open findings
What changed in this PR
This PR silences the findfont: Failed to find font weight normal, now using 600. warning that matplotlib 3.11 (pulled in by the anaconda 2026.07 bump in #102) emits to stderr and renders onto 17 lecture pages. The repository only ships the SemiBold weight of Source Han Serif SC, so matplotlib falls back to it for normal/bold text; 3.10 did this silently while 3.11 logs it. The fix raises the matplotlib.font_manager logger to ERROR immediately after the existing font registration, restoring the 3.10 output behavior without changing any rendered figures.
Changes:
- Adds
import logging # i18nandlogging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18ndirectly after thefontManager.addfontcall in each affected lecture. - Applies this consistently across all 18 lectures that register the Chinese font, following the existing trailing
# i18nconvention for zh-cn-only code.
| File | Description |
|---|---|
| lectures/about_py.md | Adds logger-silencing lines after font registration |
| lectures/debugging.md | Adds logger-silencing lines after font registration |
| lectures/functions.md | Adds logger-silencing lines after font registration |
| lectures/jax_intro.md | Adds logger-silencing lines after font registration |
| lectures/matplotlib.md | Adds logger-silencing lines after font registration |
| lectures/need_for_speed.md | Adds logger-silencing lines after font registration |
| lectures/numba.md | Adds logger-silencing lines after font registration |
| lectures/numpy.md | Adds logger-silencing lines after font registration |
| lectures/numpy_vs_numba_vs_jax.md | Adds logger-silencing lines after font registration |
| lectures/pandas.md | Adds logger-silencing lines after font registration |
| lectures/pandas_panel.md | Adds logger-silencing lines after font registration |
| lectures/python_advanced_features.md | Adds logger-silencing lines after font registration |
| lectures/python_by_example.md | Adds logger-silencing lines after font registration |
| lectures/python_oop.md | Adds logger-silencing lines after font registration |
| lectures/scipy.md | Adds logger-silencing lines after font registration |
| lectures/sympy.md | Adds logger-silencing lines after font registration |
| lectures/workspace.md | Adds logger-silencing lines after font registration |
| lectures/writing_good_code.md | Adds logger-silencing lines after font registration |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Refs #110. This is the current fix for that issue, which stays open while other approaches are considered.
Problem
Since the anaconda 2026.07 bump (#102), matplotlib 3.11 prints
findfont: Failed to find font weight normal, now using 600.in 17 lectures, 77 times in all. It goes to stderr, so it shows on the rendered pages.The cause is that we ship only the SemiBold weight of Source Han Serif SC, and matplotlib falls back to it for normal and bold text. 3.10 did this silently; 3.11 logs it. Details are in #110.
Change
In the 18 lectures that call
fontManager.addfont, add two# i18nlines directly after the existing font registration:The lines follow the existing
# i18nconvention for zh-cn-only code. No other lines change: 36 insertions in 18 files.Effect
warningsmodule, not this logger.Testing
# i18nfont setup from each of the 18 lectures and ran it under matplotlib 3.11.0 with a figure containing Chinese normal and bold text. None printed anything.previewbuild re-executes all 18 lectures under anaconda 2026.07. Their outputs should no longer containfindfont.🤖 Generated with Claude Code
https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb
Generated by Claude Code