Python Matplotlib Chinese Font Configuration for Openclaw

A comprehensive solution for resolving Chinese character rendering issues and tofu blocks in Matplotlib data visualizations.

earl-chen
v1.0.0
Apr 2, 2026
0
848
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install python-matplotlib-chinese-font

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install python-matplotlib-chinese-font using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Python Matplotlib Chinese Font Configuration?

This skill addresses the notorious issue where Matplotlib fails to render Chinese characters by default, leading to missing glyph warnings and square boxes in plots. By utilizing Openclaw Skills, developers can implement a portable, cross-platform configuration that bundles font management directly into their project workflow. It provides a standardized way to register fonts like BabelStoneHan or SimHei, ensuring that titles, legends, and axis labels appear correctly across different operating systems without relying on system-wide font installations.

Beyond just text rendering, this skill also solves common side effects such as the incorrect display of negative signs in coordinates. It focuses on best practices for Python developers, emphasizing absolute path management and version-agnostic font registration methods that work with both modern and legacy Matplotlib versions.

Python Matplotlib Chinese Font Configuration Use Cases

  • Fixing tofu blocks or scrambled text in Matplotlib visualizations.
  • Automating font configuration for data science projects using Openclaw Skills.
  • Resolving negative sign display errors in scientific charts.
  • Ensuring consistent font rendering across Windows, macOS, and Linux environments.
  • Setting up portable data visualization environments that do not depend on system fonts.

How Python Matplotlib Chinese Font Configuration Works

  1. Create a local fonts directory within the project to store required TTF files.
  2. Download a compatible Chinese font such as BabelStoneHan.ttf using CLI tools.
  3. Register the font file explicitly with the Matplotlib fontManager using the provided configuration templates.
  4. Update the global rcParams to set the default font family and disable unicode minus signs to fix negative sign rendering.
  5. Import and call the setup function at the start of any plotting script to apply the localized settings.

Python Matplotlib Chinese Font Configuration Setup

First, create a font directory and download the necessary font file:

mkdir -p fonts
curl -L -o fonts/BabelStoneHan.ttf "https://www.babelstone.co.uk/Fonts/Download/BabelStoneHan.ttf"

Next, copy the configuration template from your local Openclaw Skills repository:

cp ~/.openclaw/skills/python-matplotlib-chinese-font/templates/setup_font.py ./

Finally, initialize the font in your Python script:

from setup_font import setup_chinese_font
setup_chinese_font()

Python Matplotlib Chinese Font Configuration Data Schema & Taxonomy

The skill utilizes a structured directory pattern to maintain portability:

Component Path Description
Font Storage /fonts/ Contains the TTF files (e.g., BabelStoneHan.ttf)
Configuration /templates/ Reusable Python scripts for font registration
Utilities /references/ contains plot_utils.py for advanced plotting functions
Verification /references/ Includes test_chinese_font.py for environment validation

Python Matplotlib Chinese Font Configuration Advanced Features

  • Automatic Matplotlib version detection to choose between addfont() and legacy ttflist methods.
  • Intelligent path normalization using os.path.abspath to ensure script-relative font loading.
  • Global font cache invalidation support to force-refresh configuration changes.
  • Support for both global rcParams application and granular FontProperties control for specific plot elements.
  • Pre-configured support for multiple fonts including Microsoft YaHei and WenQuanYi Micro Hei.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*