闲社服务运行正常AI智能体自动化平台
m

matplotlib中文字体

技能标识:matplotlib-chinese-font

Configure Chinese fonts for matplotlib plotting. Use when plotting charts with Chinese characters or getting garbled text.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

matplotlib中文字体

Matplotlib 中文字体配置

何时使用

  • - matplotlib 图表中出现中文乱码(显示为方块)
  • 需要在图表中使用中文标题、标签、图例
  • 需要区分不同中文字体效果(如宋体 vs 黑体)

快速配置

方法 1:全局配置(推荐)

python
import matplotlib.pyplot as plt

配置中文字体

plt.rcParams[font.sans-serif] = [Heiti TC] # 华文黑体 plt.rcParams[axes.unicode_minus] = False # 解决负号显示问题

绘制图表

plt.plot([1, 2, 3], [1, 2, 3]) plt.title(测试标题, fontsize=14) plt.xlabel(X 轴) plt.ylabel(Y 轴) plt.show()

方法 2:强制指定字体(更可靠)

当全局配置不生效时,在具体元素上强制指定:

python
plt.title(图表标题, fontsize=14, fontname=Heiti TC)
plt.xlabel(X 轴, fontsize=12, fontname=Heiti TC)
plt.ylabel(Y 轴, fontsize=12, fontname=Heiti TC)
plt.text(0.5, 0.5, 文本标注, fontname=Heiti TC)

可用字体

常用系统字体:

  • - Heiti TC - 华文黑体(用户偏好)
  • Songti SC - 华文宋体

查询所有可用字体:
bash
python3 -c import matplotlib.font_manager as fm; print(\n.join(sorted(set([f.name for f in fm.fontManager.ttflist]))))

常见问题

字体不生效

  1. 1. 清除字体缓存
bash rm -rf ~/.matplotlib

或运行 scripts/clear_cache.py

  1. 2. 强制指定字体
使用 fontname 参数而不是 rcParams
  1. 3. 检查字体是否存在
运行 scripts/list_fonts.py 查看系统可用字体

负号显示为方块

python
plt.rcParams[axes.unicode_minus] = False

保存图片时中文乱码

确保保存前字体已正确设置:
python
plt.savefig(/tmp/chart.png, dpi=120, bbox_inches=tight)

脚本工具

  • - scripts/clearcache.py - 清除 matplotlib 字体缓存
  • scripts/listfonts.py - 列出系统可用中文字体
  • scripts/test_font.py - 测试指定字体的显示效果

参考资料

  • - references/troubleshooting.md - 详细问题排查指南

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 matplotlib-chinese-font-1776177442 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 matplotlib-chinese-font-1776177442 技能

通过命令行安装

skillhub install matplotlib-chinese-font-1776177442

下载

⬇ 下载 matplotlib-chinese-font v1.0.0(免费)

文件大小: 5.17 KB | 发布时间: 2026-4-15 12:50

v1.0.0 最新 2026-4-15 12:50
- Initial release of matplotlib-chinese-font.
- Provides guidance for configuring Chinese fonts in matplotlib to avoid garbled text.
- Includes quick configuration methods (global and element-wise) for Chinese labels and titles.
- Offers troubleshooting steps for common font display issues and negative sign rendering.
- Adds script utilities for clearing font cache, listing available fonts, and testing font display.
返回顶部