Skip to content

Re-apply CJK font after style/theme resets in matplotlib and pandas_panel - #87

Merged
mmcky merged 1 commit into
mainfrom
fix-cjk-font-clobber
Aug 7, 2026
Merged

Re-apply CJK font after style/theme resets in matplotlib and pandas_panel#87
mmcky merged 1 commit into
mainfrom
fix-cjk-font-clobber

Conversation

@mmcky

@mmcky mmcky commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Two lectures carry correct CJK font configuration in their i18n import cells and still ship tofu on the published site — including after the 2026-08-03 publish, which proves the defect is in the executed code, not a stale build cache.

Mechanism: plt.style.use() and sns.set_theme() both reset font.family to their own defaults, silently discarding the Source Han Serif SC configuration set earlier in the lecture. matplotlib does not fail on a missing glyph — it warns into stderr and substitutes blank boxes, so the build stays green.

Fixes (one line each):

  • matplotlib.md — re-apply font.family inside draw_graphs after each plt.style.use(style), so the CJK suptitle (样式:…) renders under every demo style.
  • pandas_panel.md — pass the font family through sns.set_theme(rc=...), seaborn's documented override mechanism, keeping the theme and the font both.

Verification: the Netlify preview's matplotlib and pandas_panel pages should show no Glyph … missing from font(s) stderr output, and bin/check-tofu --site (from the program bench) against the preview should report both pages clean. Part of the publish-gate work tracked in QuantEcon/project-translation#25; after merge, the pages come clean on the next cache run + republish.

🤖 Generated with Claude Code

…anel

plt.style.use() and sns.set_theme() reset font.family to their own
defaults, silently discarding the Source Han Serif SC configuration set
in the i18n import cell. The result ships as tofu: both pages still
render blank boxes on the published site after the 2026-08-03 publish,
because the defect is in the executed code, not a stale build cache.

matplotlib.md: re-apply font.family inside draw_graphs after each
plt.style.use(style), so the CJK suptitle renders under every demo style.
pandas_panel.md: pass the font family through sns.set_theme(rc=...),
seaborn's documented override mechanism.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes CJK “tofu” (missing glyph boxes) in the published lecture site by ensuring the intended CJK font configuration survives matplotlib/seaborn style and theme resets.

Changes:

  • lectures/matplotlib.md: re-applies plt.rcParams['font.family'] immediately after plt.style.use(style) inside draw_graphs, so the CJK suptitle renders under every style sheet.
  • lectures/pandas_panel.md: passes font.family via sns.set_theme(rc=...) so seaborn’s theme setup doesn’t discard the CJK font configuration.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lectures/matplotlib.md Restores CJK font family after plt.style.use() resets rcParams.
lectures/pandas_panel.md Preserves CJK font family through seaborn theme initialization via rc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mmcky
mmcky merged commit 0153f28 into main Aug 7, 2026
3 checks passed
@mmcky
mmcky deleted the fix-cjk-font-clobber branch August 7, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants