You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix tofu in Chinese figure labels, and give font.family a fallback (#206)
* Restore the CJK font block in three lectures (#205)
These three lectures set Chinese text on their figures but never register a
CJK font, so matplotlib falls back to DejaVu Sans — which has no CJK coverage
— and every Chinese axis label, title and legend entry renders as blank boxes
("tofu"). Nothing errors and a valid PNG is written, so the build stays green
and the defect only shows up in the published output.
Affected labels include 密度 / KL散度 / JS散度 / 切尔诺夫熵 in
divergence_measures.md, 收益率 / 日期 / 时间 / 对数秩 / 对数规模 in
kesten_processes.md, and the subplot titles 价值函数 / $s$策略 / $\phi$策略
in jv.md.
Adds this edition's standard block to the first code cell that imports
matplotlib in each file, immediately after `import matplotlib.pyplot as plt`
so it runs before any figure is drawn:
import matplotlib as mpl
FONTPATH = "fonts/SourceHanSerifSC-SemiBold.otf"
mpl.font_manager.fontManager.addfont(FONTPATH)
plt.rcParams['font.family'] = ['Source Han Serif SC']
Matches the convention already used by the other 112 lectures here (see
aiyagari.md); the path resolves against lectures/, where
fonts/SourceHanSerifSC-SemiBold.otf is checked in. Same class of gap as the
five lectures fixed in #196 — nothing else in these files is touched.
See #205
* Add a DejaVu fallback to font.family, and register the font in two more lectures
Setting font.family to a single entry removes matplotlib's fallback, so any
character the CJK font lacks renders as a blank box. Source Han Serif SC follows
Adobe-GB1, which omits subscript digits (U+2080-2083), the vertical ellipsis
(U+22EE), and the lunate/symbol Greek forms (U+03F5 epsilon, U+03D5 phi) — all
of which these lectures use in figure labels.
Measured on matplotlib 3.11.1 with this repo's own font, rendering a label
containing 密钥拆分树, key₀, ⋮, ϵ and ϕ:
font.family = ['Source Han Serif SC'] -> 4 missing-glyph warnings
font.family = ['Source Han Serif SC', 'DejaVu Sans'] -> 0
Two lectures already carried the block and were silently losing characters to
it: career.md sets ylabel='ϵ' (and label='ϵ'), affine_risk_prices.md builds
label=f"... (r₁ = ...)". Both are fixed by the fallback alone.
This deviates from the single-entry dialect used elsewhere in the edition. That
is deliberate: the dialect is missing a fallback, and adding one is strictly an
improvement everywhere it appears.
0 commit comments