
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.