Skip to content

Commit 87fcd31

Browse files
mmckyclaude
andauthored
Silence matplotlib 3.11's font-weight fallback warning in the i18n font cells (#111)
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 Claude-Session: https://claude.ai/code/session_01Wyb6EzbNzY5a8uuJPnDtUb Co-authored-by: Claude <[email protected]>
1 parent a561ca1 commit 87fcd31

18 files changed

Lines changed: 36 additions & 0 deletions

‎lectures/about_py.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ import matplotlib as mpl # i18n
306306
import matplotlib.font_manager # i18n
307307
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
308308
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
309+
import logging # i18n
310+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
309311
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
310312
311313
a = np.linspace(-np.pi, np.pi, 100) # 创建从 -π 到 π 的均匀网格

‎lectures/debugging.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import matplotlib as mpl # i18n
7575
import matplotlib.font_manager # i18n
7676
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
7777
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
78+
import logging # i18n
79+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
7880
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
7981
```
8082

‎lectures/functions.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import matplotlib as mpl # i18n
6565
import matplotlib.font_manager # i18n
6666
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
6767
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
68+
import logging # i18n
69+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
6870
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
6971
```
7072

‎lectures/jax_intro.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import matplotlib as mpl # i18n
7575
import matplotlib.font_manager # i18n
7676
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
7777
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
78+
import logging # i18n
79+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
7880
mpl.rcParams['font.family'] = ['Source Han Serif SC', 'DejaVu Sans'] # i18n
7981
import numpy as np
8082
import quantecon as qe

‎lectures/matplotlib.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import matplotlib as mpl # i18n
8080
import matplotlib.font_manager # i18n
8181
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
8282
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
83+
import logging # i18n
84+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
8385
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
8486
8587
x = np.linspace(0, 10, 200)

‎lectures/need_for_speed.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ import matplotlib as mpl # i18n
9292
import matplotlib.font_manager # i18n
9393
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
9494
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
95+
import logging # i18n
96+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
9597
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
9698
import random
9799
```

‎lectures/numba.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import matplotlib as mpl # i18n
5656
import matplotlib.font_manager # i18n
5757
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
5858
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
59+
import logging # i18n
60+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
5961
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
6062
```
6163

‎lectures/numpy.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ import matplotlib as mpl # i18n
8585
import matplotlib.font_manager # i18n
8686
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
8787
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
88+
import logging # i18n
89+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
8890
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
8991
from mpl_toolkits.mplot3d.axes3d import Axes3D
9092
from matplotlib import cm

‎lectures/numpy_vs_numba_vs_jax.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ import matplotlib as mpl # i18n
8181
import matplotlib.font_manager # i18n
8282
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
8383
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
84+
import logging # i18n
85+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
8486
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
8587
from mpl_toolkits.mplot3d.axes3d import Axes3D
8688
from matplotlib import cm

‎lectures/pandas.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import matplotlib.font_manager # i18n
8686
import requests
8787
FONTPATH = "_fonts/SourceHanSerifSC-SemiBold.otf" # i18n
8888
mpl.font_manager.fontManager.addfont(FONTPATH) # i18n
89+
import logging # i18n
90+
logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) # i18n
8991
mpl.rcParams['font.family'] = ['Source Han Serif SC'] # i18n
9092
```
9193

0 commit comments

Comments
 (0)