Skip to content

Silence matplotlib 3.11's font-weight fallback warning in the i18n font cells - #111

Merged
mmcky merged 1 commit into
mainfrom
claude/funny-hamilton-3j8jve
Oct 13, 2026
Merged

mmcky merged 1 commit into
mainfrom
claude/funny-hamilton-3j8jve

Conversation

@mmcky

@mmcky mmcky commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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 # i18n lines directly after the existing font registration:

import logging  # i18n
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR)  # i18n

The lines follow the existing # i18n convention for zh-cn-only code. No other lines change: 36 insertions in 18 files.

Effect

  • The font manager's lookup messages are hidden, which restores the 3.10 behaviour.
  • Figures are unchanged. The fallback still uses the SemiBold face, and a PNG drawn with and without the warning is byte-identical.
  • Missing glyphs are still reported, because matplotlib raises them through Python's warnings module, not this logger.

Testing

  • I extracted the # i18n font 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.
  • This PR's preview build re-executes all 18 lectures under anaconda 2026.07. Their outputs should no longer contain findfont.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb


Generated by Claude Code

…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

Copilot AI left a comment

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.

🟢 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 # i18n and logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n directly after the fontManager.addfont call in each affected lecture.
  • Applies this consistently across all 18 lectures that register the Chinese font, following the existing trailing # i18n convention 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.

@mmcky
mmcky merged commit 87fcd31 into main Oct 13, 2026
3 checks passed
@mmcky
mmcky deleted the claude/funny-hamilton-3j8jve branch October 13, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants