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
If the global font size is set with plt.rcParams["font.size"] and the size value >12, the Chinese charaters will show, else the Chinese characteres will disappear.
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltplt.rcParams["font.family"] = ["Times New Roman", "SimSun"]
plt.rcParams["font.serif"] = ["Times New Roman", "SimSun"]
plt.rcParams["font.sans-serif"] = ["Times New Roman", "SimSun", "Arial", "SimHei"]
plt.rcParams["mathtext.fontset"] ="custom"plt.rcParams["axes.unicode_minus"] =Falseplt.rcParams["font.size"] =13# If font size <= 12, the Chinese characters will not show.x=np.array([1, 2, 3, 4, 5])
y=np.array([1, 4, 9, 16, 25])
plt.plot(x, y)
plt.xlabel('X-axis / X 轴')
plt.ylabel('Y-axis / Y 轴')
plt.title('Font Style Example / 字体样式示例')
plt.show()
Actual outcome
"# plt.rcParams["font.size"] = 13"
"plt.rcParams["font.size"] = 13"
Expected outcome
Font fallback can work correctly. The text containing Chinese characters and Non-Chinese characters can be diplayed with SimSun font and Time New Roman font, respectively.
Additional information
Font fallback is incompatible for SimSun and Times New Roman fonts.
Hi @dragoneptech , thank you for reporting this issue. I am interested in investigating this font fallback behavior. I will attempt to reproduce it locally to understand why the Chinese characters disappear when the font size is 12 or smaller. I’ll keep you updated on my findings.
Hi @dragoneptech , thank you for reporting this issue. I am interested in investigating this font fallback behavior. I will attempt to reproduce it locally to understand why the Chinese characters disappear when the font size is 12 or smaller. I’ll keep you updated on my findings.
I have successfully reproduced this bug locally.
I enabled debug logging for matplotlib.font_manager and observed that both Times New Roman and SimSun are successfully matched with a perfect score (0.05). This indicates the font manager is working correctly.
Hypothesis: The issue seems to be in the FreeType rendering phase. SimSun contains embedded bitmap strikes for smaller sizes (<= 12). It appears that the font fallback mechanism in Matplotlib fails when trying to render a mix of vector glyphs (Times New Roman) and embedded bitmap glyphs (SimSun at small sizes), causing the fallback text to disappear completely. When size >12, SimSun uses vector outlines, and the fallback works fine.
I am now looking into how ft2font and the backend handle this mixed rendering.
Hii @dragoneptech
I have submitted a fix for this issue in PR #32072. The fix involves forcing the FT_LOAD_NO_BITMAP flag in FT2Font::load_glyph to ensure vector outlines are used for small font sizes. Looking forward to your feedback!
FreeType returns embedded bitmap glyphs as 0 or 1 per pixel, but Agg needs an alpha of 0 to 255. RendererAgg._draw_text_glyphs_and_boxes incorrectly only scales when antialiasing is off, so with antialiasing on we draw these glyphs at a near-invisible alpha of 1 instead of 255.
FT_Load_Glyph only applies its transform to outlines, and the offset and rotation set by _set_transform are silently dropped for a bitmap, so bitmaps render at the origin (wrong location).
Suggested fix for both: Add an attribute to _PositionedBitmap that says whether the glyph came from an embedded bitmap. Based on that, _draw_text_glyphs_and_boxes can scale the alpha value and add in the offset it already computed, since FreeType only applies that to outlines right now.
However! This still does not allow for rotating or slanting the bitmaps, and resampling those would be quite a bit more scope. So FT_LOAD_NO_BITMAP should still be set true (as in #32072) so that we prefer outlines - per the freetype source this flag is ignored for bitmap-only fonts.
For tests this may require defining a custom bitmap-only font as a test fixture, since I can't find any of the packaged fonts that are bitmap only (it's uncommon, which is why this went unnoticed so long). SimSun is windows only and so can't be relied on for testing.
This isn't limited to font fallback or CJK fonts. Any font with embedded bitmap strikes renders blank text at those pixel sizes when it's the primary font. Calibri (default on Windows) is a common example: its strikes are at 12, 13, 15, 16, 17 and 19 ppem, and every one of those sizes renders blank in Agg.
In practice, 9 pt text at dpi=150 (18.75 → 19 px) disappears entirely: tick labels, axis labels and the legend. Mathtext still renders. Saving at dpi=300 hides the problem, so the inline/Jupyter view is broken while the exported figure looks fine.
3.10.9 blank at ppem: []
3.11.1 blank at ppem: [12, 13, 15, 16, 17, 19]
3.11.2 blank at ppem: [12, 13, 15, 16, 17, 19]
Windows 11, Python 3.14, FreeType 2.14.3 (bundled), Agg backend. Changing text.hinting makes no difference. This regressed in 3.11.0, and the analysis above (bitmap glyphs drawn at alpha 1, plus FT_LOAD_NO_BITMAP as the fix) fits this case.
Workarounds: downgrade to matplotlib<3.11, use different resolutions (ex: 144 instead of 150).
Activity
mohit-sharma-001 commentedon Jul 19, 2026
Hi @dragoneptech , thank you for reporting this issue. I am interested in investigating this font fallback behavior. I will attempt to reproduce it locally to understand why the Chinese characters disappear when the font size is 12 or smaller. I’ll keep you updated on my findings.
mohit-sharma-001 commentedon Jul 19, 2026
I have successfully reproduced this bug locally.
I enabled debug logging for matplotlib.font_manager and observed that both Times New Roman and SimSun are successfully matched with a perfect score (0.05). This indicates the font manager is working correctly.
Hypothesis: The issue seems to be in the FreeType rendering phase. SimSun contains embedded bitmap strikes for smaller sizes (<= 12). It appears that the font fallback mechanism in Matplotlib fails when trying to render a mix of vector glyphs (Times New Roman) and embedded bitmap glyphs (SimSun at small sizes), causing the fallback text to disappear completely. When size >12, SimSun uses vector outlines, and the fallback works fine.
I am now looking into how ft2font and the backend handle this mixed rendering.
mohit-sharma-001 commentedon Jul 19, 2026
Hii @dragoneptech
I have submitted a fix for this issue in PR #32072. The fix involves forcing the FT_LOAD_NO_BITMAP flag in FT2Font::load_glyph to ensure vector outlines are used for small font sizes. Looking forward to your feedback!
sahil-11116 commentedon Jul 23, 2026
Hi I'm a new contributor to Matplotlib and would like to take this documentation issue. I'd appreciate any guidance or suggestions on where to begin.
QuLogic commentedon Jul 23, 2026
@sahil-11116 There is an existing PR (linked above) by @mohit-sharma-001 and we tend to focus on the first one, unless it goes stale and orphaned.
mohit-sharma-001 commentedon Jul 24, 2026
@QuLogic Thanks for your observation
If there needs to be an change please feel free to contact me
scottshambaugh commentedon Jul 25, 2026
I looked into this and found the underlying issue.
Relevant code:
matplotlib/lib/matplotlib/backends/backend_agg.py
Lines 180 to 199 in 357b274
There are actually two bugs here:
FreeType returns embedded bitmap glyphs as 0 or 1 per pixel, but Agg needs an alpha of 0 to 255.
RendererAgg._draw_text_glyphs_and_boxesincorrectly only scales when antialiasing is off, so with antialiasing on we draw these glyphs at a near-invisible alpha of 1 instead of 255.FT_Load_Glyphonly applies its transform to outlines, and the offset and rotation set by_set_transformare silently dropped for a bitmap, so bitmaps render at the origin (wrong location).Suggested fix for both: Add an attribute to
_PositionedBitmapthat says whether the glyph came from an embedded bitmap. Based on that,_draw_text_glyphs_and_boxescan scale the alpha value and add in the offset it already computed, since FreeType only applies that to outlines right now.However! This still does not allow for rotating or slanting the bitmaps, and resampling those would be quite a bit more scope. So
FT_LOAD_NO_BITMAPshould still be set true (as in #32072) so that we prefer outlines - per the freetype source this flag is ignored for bitmap-only fonts.For tests this may require defining a custom bitmap-only font as a test fixture, since I can't find any of the packaged fonts that are bitmap only (it's uncommon, which is why this went unnoticed so long). SimSun is windows only and so can't be relied on for testing.
Demo plot that claude threw together:
spalato commentedon Nov 18, 2026
This isn't limited to font fallback or CJK fonts. Any font with embedded bitmap strikes renders blank text at those pixel sizes when it's the primary font. Calibri (default on Windows) is a common example: its strikes are at 12, 13, 15, 16, 17 and 19 ppem, and every one of those sizes renders blank in Agg.
In practice, 9 pt text at dpi=150 (18.75 → 19 px) disappears entirely: tick labels, axis labels and the legend. Mathtext still renders. Saving at dpi=300 hides the problem, so the inline/Jupyter view is broken while the exported figure looks fine.
output:
Windows 11, Python 3.14, FreeType 2.14.3 (bundled), Agg backend. Changing text.hinting makes no difference. This regressed in 3.11.0, and the analysis above (bitmap glyphs drawn at alpha 1, plus FT_LOAD_NO_BITMAP as the fix) fits this case.
Workarounds: downgrade to
matplotlib<3.11, use different resolutions (ex: 144 instead of 150).Disable loading of bitmap glyphs for raster outputs
Disable loading of bitmap glyphs for raster outputs
Disable loading of bitmap glyphs for raster outputs