Japanize Matplotlib
Japanize Matplotlib (version 1.1.3) is a Python library that automatically configures Matplotlib to display Japanese fonts correctly. It simplifies the process of handling Japanese text in plots by applying a default font (IPAexGothic) to Matplotlib's settings upon import. The library is currently in maintenance mode, with the last major update in October 2020.
Common errors
-
import japanize_matplotlib したのに日本語表示になりません
cause Another plotting library or custom Matplotlib configuration overwrites the font settings applied by `japanize_matplotlib` after its import.fixMove `import japanize_matplotlib` to be the last import statement related to plotting, or call `japanize_matplotlib.japanize()` after any code that might modify font settings (e.g., `sns.set()`). -
PackagesNotFoundError: The following packages are not available from current channels: - japanize-matplotlib
cause The `japanize-matplotlib` package, especially for certain OS/architectures (e.g., Windows), might not be available in the specified Conda channel.fixIf encountering this with Conda, try installing via pip: `pip install japanize-matplotlib`. This is often a reliable fallback for packages not fully supported across all Conda environments.
Warnings
- gotcha Importing `japanize_matplotlib` might be ineffective if other plotting libraries (e.g., Seaborn) are initialized afterward and override Matplotlib's font settings.
- gotcha Linters or code formatters may remove the `import japanize_matplotlib` line if they deem it unused, as its effect is side-dependent.
Install
-
pip install japanize-matplotlib -
conda install -c uehara1414 japanize-matplotlib
Imports
- japanize_matplotlib
import japanize_matplotlib
Quickstart
import matplotlib.pyplot as plt
import japanize_matplotlib
plt.plot([1, 2, 3, 4])
plt.xlabel('簡単なグラフ (Simple Graph)')
plt.ylabel('値 (Value)')
plt.title('日本語タイトル (Japanese Title)')
plt.grid(True)
plt.show()