Re-apply CJK font after style/theme resets in matplotlib and pandas_panel - #87
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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-appliesplt.rcParams['font.family']immediately afterplt.style.use(style)insidedraw_graphs, so the CJK suptitle renders under every style sheet.lectures/pandas_panel.md: passesfont.familyviasns.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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()andsns.set_theme()both resetfont.familyto 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-applyfont.familyinsidedraw_graphsafter eachplt.style.use(style), so the CJK suptitle (样式:…) renders under every demo style.pandas_panel.md— pass the font family throughsns.set_theme(rc=...), seaborn's documented override mechanism, keeping the theme and the font both.Verification: the Netlify preview's
matplotlibandpandas_panelpages should show noGlyph … missing from font(s)stderr output, andbin/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