yum -y install ipa-gothic-fonts ipa-mincho-fonts ipa-pgothic-fonts ipa-pmincho-fonts
rm fontList.py3.cache # Python 3]
/usr/share/fonts/ipa-pgothic/ipagp.ttf
import matplotlib
from matplotlib.font_manager import FontProperties
font_path = './TakaoPGothic.ttf' #DLしたパスを指定. /font以下でなくても良い
font_path = '/usr/share/fonts/ipa-pgothic/ipagp.ttf'
font_prop = FontProperties(fname=font_path)
例
plt.text(X[i, 0], X[i, 1], hoge, fontproperties=font_prop)
他のブログでは、matplotlibの環境ファイルであるmatplotlibrcファイルのfont.familyの箇所を、DLしたフォント名で指定して、使用するフォントを書き換えているがmatplotrcファイルを書き換えることができない弱い権限のときは plotする時にいちいち引数にfontproperties=font_propを渡してあげることで解決している
(※いちいち引数に書くのはややめんどくさくはあるが、そこまで頻繁にmatplotlibで日本語表示をしない人は、環境ファイルを書き換えて何かよくわからんことになってしまうより、暫定的に変更する方がむしろ楽かもしれない)
fontproperties=font_propをいちいち渡して日本語表示する際の注意点としては、
plt.legendするときだけfontproperties=font_propではなく、prop=font_propとなる点。
例
plt.legend(['hoge'], prop=font_prop, loc='upper left')
(備考)MatplotlibのFontキャッシュ削除
Fontのキャッシュが残っていると、設定変更しても反映されない可能性があるのでこれを削除する
$ rm ~/.cache/matplotlib/fontList.cache