LoginSignup
24
14

More than 5 years have passed since last update.

ubuntuでmatplotlibのfontを設定

Last updated at Posted at 2016-06-13

UbuntuにあるFontをチェック

フォントの一覧表示

fc-list|less

自分が使いたいフォントがあるかどうかをチェック

例:Takaoを含むフォントがあるかどうか

fc-list|less | grep Takao

必要なフォントをダウンロード

https://github.com/blagarde/midori/blob/master/fonts-japanese-gothic.ttf
https://github.com/marcan/blitzloop/blob/master/TakaoPGothic.ttf <- これがなくなってたので以下のを試した(2017/10/07)

今回はこの2つをダウンロード

ダウンロードしたフォントを配置

上の2つを置いてあるディレクトリ上で、以下を/usr/local/share/fonts/へコピー

cp *ttf /usr/local/share/fonts/

matplotlibの設定ファイルにfontを設定

設定ファイルの位置は以下で確認

>>> import matplotlib
>>> matplotlib.matplotlib_fname()
'/home/foo/.config/matplotlib/matplotlibrc'

~/.config/matplotlib/matplotlibrcに以下を書けば良い、

font.family: (自分の使いたいフォント)

今回は、

font.family: TakaoPGothic

とした。

MatplotlibのFontキャッシュ削除

最後に、matplotlibで日本語を描画 on Ubuntu の記事であった大事なこと!

Fontのキャッシュを削除

rm ~/.cache/matplotlib/fontList.cache

ファイル名が異なる場合もあるので、~/.cache/matplotlib/以下でfontListがついてるファイルを見つけて削除する

24
14
0

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
24
14