matplotlib-fontja is a Python library designed to easily enable Japanese character display in Matplotlib plots. It automatically detects available Japanese fonts on your system, updates Matplotlib's font cache, and configures `rcParams` to use them. The current version is 1.1.0, with updates typically focusing on compatibility and font detection improvements.
pip install matplotlib-fontjaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import `matplotlib-fontja`, apply its font configuration using `set_font()`, and then create a Matplotlib plot that correctly displays Japanese characters.
Ensure you have Japanese fonts (e.g., Noto Sans CJK, Yu Gothic, Meiryo) installed on your system. For Linux, refer to your distribution's font installation guides.
If Japanese characters still appear as squares, try restarting your Python kernel or development environment. In rare cases, manually clearing the Matplotlib font cache might be necessary: `import matplotlib.font_manager; matplotlib.font_manager._rebuild();`
Call `matplotlib_fontja.set_font()` early in your script or notebook, ideally before any custom `rcParams` modifications that might conflict with font settings. If you need to override a specific font setting, do so after `set_font()`.
Install common Japanese fonts (e.g., Noto Sans CJK JP, Meiryo, Yu Gothic) on your OS. The specific installation method varies by OS (e.g., `apt install fonts-noto-cjk-extra` on Debian/Ubuntu, installing font files on Windows/macOS).
First, ensure Japanese fonts are installed on your OS. Then, make sure `matplotlib_fontja.set_font()` is called before `plt.show()`. If the problem persists, restart your Python environment and consider manually rebuilding the font cache: `import matplotlib.font_manager; matplotlib.font_manager._rebuild();`