Skip to content

matplotlib 3.11 prints "findfont: Failed to find font weight normal" on 17 lectures #110

Open

Description

@mmcky

Since the anaconda 2026.07 bump (#102), matplotlib 3.11 prints this line in the output of 17 lectures, 77 times in all:

findfont: Failed to find font weight normal, now using 600.

The line goes to stderr. This repo shows stderr output (nb_merge_streams: true), so readers see it on the rendered pages. It does not fail the build, so CI stays green.

Where

These numbers come from the cache.yml run on a561ca1, the first full execution under anaconda 2026.07 (matplotlib 3.11.0). Its executed notebooks were compared with the previous run under 2025.12 (matplotlib 3.10.6), which had none of these lines.

Lecture Occurrences
jax_intro 11
matplotlib 9
python_oop 8
numba 6
numpy_vs_numba_vs_jax, pandas_panel, python_advanced_features, scipy, sympy 5 each
numpy 4
pandas, workspace, writing_good_code 3 each
python_by_example 2
about_py, debugging, functions 1 each

need_for_speed also registers the font but printed nothing in this run.

Cause

The repo ships one weight of the Chinese font, lectures/_fonts/SourceHanSerifSC-SemiBold.otf, weight 600. The # i18n cells register it and make it the default family:

mpl.font_manager.fontManager.addfont(FONTPATH)  # i18n
mpl.rcParams['font.family'] = ['Source Han Serif SC']  # i18n

Normal text asks for weight 400 and bold text for 700. Both matplotlib versions fall back to the only weight there is, 600. Version 3.10 did so silently; 3.11 logs a warning through the matplotlib.font_manager logger each time.

The fallback itself is unchanged. With the same font cell and a figure containing Chinese labels:

Output Figure
matplotlib 3.10.6 nothing printed
matplotlib 3.11.0 findfont: Failed to find font weight normal, now using 600. and the same line for bold byte-identical PNG to 3.11 with the warning silenced

Proposed fix

Add two # i18n lines next to the existing font registration, in the 18 lectures that call fontManager.addfont:

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

This silences only the font manager's lookup messages, which restores the 3.10 behaviour. A missing glyph is still reported, because matplotlib raises that through Python's warnings module, not this logger. Tested under 3.11.0: no output, and an identical figure.

Alternatives considered:

  • mpl.rcParams['font.weight'] = 'semibold': does not help. Legends and labels still ask for normal and bold text for bold, so the warnings remain. It also adds a new warning where DejaVu Sans is the fallback family, because DejaVu has no semibold weight.
  • Shipping a Regular (and Bold) weight: fixes the cause, but each weight is about 24 MB, and the figures look the same either way.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb

Activity

  1. mmcky commented on Oct 13, 2026

    @mmcky
    ContributorAuthor

    The current fix is in #111. It adds the two # i18n lines proposed above to the 18 lectures that register the font, so matplotlib's font manager logs only errors:

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

    This hides the findfont lines without changing any figure. It treats the symptom, though: we still ship only the SemiBold weight, and matplotlib still falls back to it for normal and bold text.

    #111 references this issue without a closing keyword, so this stays open while other matplotlib approaches are considered. Options include shipping a proper Regular and Bold weight, or configuring the font another way. If one of those is adopted, the two lines can come back out.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions