From 6160d0c8ae040bd117f0beecde421b509a1815ba Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Mon, 24 Aug 2026 21:36:40 +1000 Subject: [PATCH] Register the CJK font in util_rand_resp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lecture draws five figures whose labels, legends and annotations are Chinese — 真话边界, 诚实回答, 说谎, 等方差曲线, 最优设计 — but it is one of 36 lectures carrying no i18n font registration, so matplotlib falls back to DejaVu Sans, which has no CJK glyphs. This surfaced on publish-2026aug24b. The previous release rendered the page from an execution cached on 2026-08-17 and showed no warning; the 2026-08-24 cache run executed it afresh and emitted 19 missing-glyph warnings, losing 优回实差方曲最界真等答线计设诚话说谎边. The lecture text never changed — only the environment it was executed in — so the tofu was latent rather than new, and re-execution exposed it. Use the same block as career.md, with the DejaVu fallback retained because this lecture mixes Chinese labels with LaTeX math and Latin axis text. Of the 36 lectures with no font registration this is the only one with Chinese inside plotting calls; the other 35 are latent and would break the same way if labels were ever translated. Refs #205 Co-Authored-By: Claude Opus 5 (1M context) --- lectures/util_rand_resp.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lectures/util_rand_resp.md b/lectures/util_rand_resp.md index 85336a3f..2a3d09a2 100644 --- a/lectures/util_rand_resp.md +++ b/lectures/util_rand_resp.md @@ -50,6 +50,11 @@ Lars Ljungqvist {cite}`ljungqvist1993unified` 分析了受访者是否如实回 ```{code-cell} ipython3 import matplotlib.pyplot as plt +import matplotlib as mpl +FONTPATH = "fonts/SourceHanSerifSC-SemiBold.otf" +mpl.font_manager.fontManager.addfont(FONTPATH) +plt.rcParams['font.family'] = ['Source Han Serif SC', 'DejaVu Sans'] + import numpy as np ```