
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
matplotlibを日本語表示に対応させます。
uehara1414さんのjapanize-matplotlibをフォークし、Python 3.12以降でも動作するよう修正したものです。変更点の詳細についてはCHANGELOGをお読みください。
matplotlibをimportした後、matplotlib_fontjaをimportします。
import matplotlib.pyplot as plt
import matplotlib_fontja
plt.plot([1, 2, 3, 4])
plt.xlabel('簡単なグラフ')
plt.show()
# pipを使う場合
pip install matplotlib-fontja
# uvを使う場合
uv add matplotlib-fontja
# Ryeを使う場合
rye add matplotlib-fontja
# Pipenvを使う場合
pipenv install matplotlib-fontja
# Poetryを使う場合
poetry add matplotlib-fontja
# Condaを使う場合
conda install conda-forge::matplotlib-fontja
以下のPythonとMatplotlibのバージョンの組み合わせで動作を確認しています。
IPAexゴシック (Ver.004.01) を利用しています。 利用にあたってはIPAフォントライセンスv1.0に同意してください。
import matplotlib_fontja
したのに日本語が表示されませんimport matplotlib_fontja
してからグラフを描画するまでにフォントの設定が変わる処理が入っている可能性があります。
例えば、seabornを使用しているとsns.set_theme()
などでフォントがseabornのデフォルトに上書きされてしまいます。
以下のように、フォント上書き後にmatplotlib_fontja.japanize()
を実行してください。
sns.set_theme()
matplotlib_fontja.japanize()
seabornの場合は、sns.set_theme(font="IPAexGothic")
としてIPAexGothic
を使用するよう設定することもできます。
import matplotlib_fontja
に対してリンターの警告(F401)が出ます/フォーマッターに消されてしまいますimportしたmatplotlib_fontja
を使用していないため、不要なimportと誤判定されています。以下のようにnoqa
で無効化してください。
import matplotlib_fontja # noqa: F401
あるいは、matplotlib_fontja.japanize()
を使用すれば未使用と判定されません。無意味な実行になりますが、import直後などに追加して警告を消すこともできます。
import matplotlib_fontja
matplotlib_fontja.japanize()
matplotlibの標準機能で任意のフォントを使用できます。matplotlib-fontjaは不要です。以下はNoto Sans Japaneseを使う例です。
import matplotlib.font_manager
import matplotlib.pyplot as plt
# フォントファイルを読み込み
matplotlib.font_manager.fontManager.addfont(
"/path/to/NotoSansJP-Regular.ttf"
)
# 読み込んだフォントを使用するよう設定
matplotlib.rc("font", family="Noto Sans JP")
plt.plot([1, 2, 3, 4])
plt.xlabel('簡単なグラフ')
plt.show()
FAQs
matplotlibを日本語表示に対応させます。
We found that matplotlib-fontja demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.