-
Notifications
You must be signed in to change notification settings - Fork 356
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
生成的代码:
plt.savefig('renewal_rate_distribution.png')
遇到告警:
DeepAnalyze/demo/workspace/session_1764034961959_5wuvvxhzf/tmpx14s8q_7.py:34: UserWarning: Glyph 32493 (\N{CJK UNIFIED IDEOGRAPH-7EED}) missing from font(s) DejaVu Sans.
原因:
识别不到系统中的中文字符集
系统:Ubuntu 22
解决办法:
- 安装中文字符集:sudo apt install fonts-noto-cjk -y
- 创建一个 PYTHONSTARTUP python 文件加载字符集 :
import os
import sys
if getattr(sys.modules[__name__], '_chinese_font_setup_done', False):
pass
else:
try:
import matplotlib.pyplot as plt
from matplotlib import font_manager
font_path = "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"
if os.path.exists(font_path):
# 注册字体文件(确保 FontManager 能看到)
font_manager.fontManager.addfont(font_path)
# ✅ 关键:使用系统实际识别出的字体名称
real_name = "Noto Sans CJK JP" # ←←← 改这里!
plt.rcParams['font.sans-serif'] = [real_name, 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False
sys.modules[__name__]._chinese_font_setup_done = True
print(f"✅ Matplotlib 中文字体已启用: {real_name}", file=sys.stderr)
except Exception as e:
pass # 静默失败
- 设置环境变量:
export PYTHONSTARTUP=/llm-project/DeepAnalyze/auto_chinese_font.py - AI的帮助下试了多种办法,在我当前的环境下都不行,以上是测试通过的办法
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers