From b10ca2b2def02660ed5a4052f928032d8cf8d4fa Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 13 Oct 2026 05:26:22 +0000 Subject: [PATCH] Silence matplotlib 3.11's font-weight fallback warning in the i18n font 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 Claude-Session: https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb --- lectures/about_py.md | 2 ++ lectures/debugging.md | 2 ++ lectures/functions.md | 2 ++ lectures/jax_intro.md | 2 ++ lectures/matplotlib.md | 2 ++ lectures/need_for_speed.md | 2 ++ lectures/numba.md | 2 ++ lectures/numpy.md | 2 ++ lectures/numpy_vs_numba_vs_jax.md | 2 ++ lectures/pandas.md | 2 ++ lectures/pandas_panel.md | 2 ++ lectures/python_advanced_features.md | 2 ++ lectures/python_by_example.md | 2 ++ lectures/python_oop.md | 2 ++ lectures/scipy.md | 2 ++ lectures/sympy.md | 2 ++ lectures/workspace.md | 2 ++ lectures/writing_good_code.md | 2 ++ 18 files changed, 36 insertions(+) diff --git a/lectures/about_py.md b/lectures/about_py.md index 13aa7ee..32f4fe4 100644 --- a/lectures/about_py.md +++ b/lectures/about_py.md @@ -306,6 +306,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n a = np.linspace(-np.pi, np.pi, 100) # 创建从 -π 到 π 的均匀网格 diff --git a/lectures/debugging.md b/lectures/debugging.md index 92b6023..1ea3a3c 100644 --- a/lectures/debugging.md +++ b/lectures/debugging.md @@ -75,6 +75,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n ``` diff --git a/lectures/functions.md b/lectures/functions.md index 89328da..de8d0c8 100644 --- a/lectures/functions.md +++ b/lectures/functions.md @@ -65,6 +65,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n ``` diff --git a/lectures/jax_intro.md b/lectures/jax_intro.md index c035263..a628fdd 100644 --- a/lectures/jax_intro.md +++ b/lectures/jax_intro.md @@ -75,6 +75,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC', 'DejaVu Sans'] # i18n import numpy as np import quantecon as qe diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 8ffd244..7c58a31 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -80,6 +80,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n x = np.linspace(0, 10, 200) diff --git a/lectures/need_for_speed.md b/lectures/need_for_speed.md index 9b0fc68..b77f5fd 100644 --- a/lectures/need_for_speed.md +++ b/lectures/need_for_speed.md @@ -92,6 +92,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n import random ``` diff --git a/lectures/numba.md b/lectures/numba.md index b5d29b8..f5287c9 100644 --- a/lectures/numba.md +++ b/lectures/numba.md @@ -56,6 +56,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n ``` diff --git a/lectures/numpy.md b/lectures/numpy.md index 1709d88..ad29a4a 100644 --- a/lectures/numpy.md +++ b/lectures/numpy.md @@ -85,6 +85,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import cm diff --git a/lectures/numpy_vs_numba_vs_jax.md b/lectures/numpy_vs_numba_vs_jax.md index 870ea88..2001bea 100644 --- a/lectures/numpy_vs_numba_vs_jax.md +++ b/lectures/numpy_vs_numba_vs_jax.md @@ -81,6 +81,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import cm diff --git a/lectures/pandas.md b/lectures/pandas.md index 43cbd21..32f998c 100644 --- a/lectures/pandas.md +++ b/lectures/pandas.md @@ -86,6 +86,8 @@ import matplotlib.font_manager # i18n import requests FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n ``` diff --git a/lectures/pandas_panel.md b/lectures/pandas_panel.md index 95da282..24bbaae 100644 --- a/lectures/pandas_panel.md +++ b/lectures/pandas_panel.md @@ -50,6 +50,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n import seaborn as sns sns.set_theme(rc={'font.family': ['Source Han Serif SC', 'DejaVu Sans']}) # i18n:set_theme 会重置字体,用 rc 覆盖保留中文字体 diff --git a/lectures/python_advanced_features.md b/lectures/python_advanced_features.md index 5cb769c..5b0ad3a 100644 --- a/lectures/python_advanced_features.md +++ b/lectures/python_advanced_features.md @@ -380,6 +380,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n # 设置图框和子图 diff --git a/lectures/python_by_example.md b/lectures/python_by_example.md index a6612da..b7d61e9 100644 --- a/lectures/python_by_example.md +++ b/lectures/python_by_example.md @@ -81,6 +81,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n rng = np.random.default_rng() diff --git a/lectures/python_oop.md b/lectures/python_oop.md index 6b634d4..2a9ed9c 100644 --- a/lectures/python_oop.md +++ b/lectures/python_oop.md @@ -80,6 +80,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n ``` diff --git a/lectures/scipy.md b/lectures/scipy.md index c0a5381..f526757 100644 --- a/lectures/scipy.md +++ b/lectures/scipy.md @@ -154,6 +154,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n q = beta(5, 5) # Beta(a, b),其中 a = b = 5 diff --git a/lectures/sympy.md b/lectures/sympy.md index ac018e2..91913f5 100644 --- a/lectures/sympy.md +++ b/lectures/sympy.md @@ -79,6 +79,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n # 启用 mathjax 打印器 diff --git a/lectures/workspace.md b/lectures/workspace.md index 7199b2f..04e9f4a 100644 --- a/lectures/workspace.md +++ b/lectures/workspace.md @@ -77,6 +77,8 @@ import numpy as np FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n x = np.linspace(0, 10, 100) diff --git a/lectures/writing_good_code.md b/lectures/writing_good_code.md index 2f7be27..5c65cf0 100644 --- a/lectures/writing_good_code.md +++ b/lectures/writing_good_code.md @@ -91,6 +91,8 @@ import matplotlib as mpl # i18n import matplotlib.font_manager # i18n FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n mpl.font_manager.fontManager.addfont(FONTPATH) # i18n +import logging # i18n +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n # 为时间序列分配内存