2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Docker環境のJupyterのMatplotlibで日本語フォントを使用する

Last updated at Posted at 2021-10-31

動機

タイトルがややこしい・・。最新の情報ではMatplotlibに日本語フォントがバンドルされているので、オプションを変更したら使えるよという記事などで試すも、うまく動作せず旧来の方法で普通にインストールすることにしました。
Exactryな記事がなかった気がするのでDockerコンテナで開発環境を整えていて、かつ簡単に解決したい方にお届けします。

ご注意
動作を確認したDockerイメージはcontinuumio/anaconda3なのでdebian系です。他のOSではフォントの格納場所の都合で動作しない可能性があります。報告いただくか、自分で試したら追記していきます。

Dockerファイルへの追記内容

以下をDockerfileのどこかに記載してください。Matplotlibはご自身でインストールしている前提となります。

# フォントインストール
RUN wget https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKjp-hinted.zip -O /tmp/fonts_noto.zip && \
    mkdir -p /usr/share/fonts &&\
    unzip /tmp/fonts_noto.zip -d /usr/share/fonts

使い方

参考までにJupyterでの使用例を紹介します。

import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'Noto Sans JP'
plt.plot([1,2],label="ラベル")
plt.title("日本語が使えます")
plt.legend()

Screen Shot 2021-10-31 at 22.28.40.png

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?