https://estuarine.jp/2016/09/jp-fonts-matplotlib/
yum -y install ipa-gothic-fonts ipa-mincho-fonts ipa-pgothic-fonts ipa-pmincho-fonts
rm fontList.py3.cache # Python 3]
https://qiita.com/ysdyt/items/3eb9b438980409c8f3e2
/usr/share/fonts/ipa-pgothic/ipagp.ttf
import matplotlib from matplotlib.font_manager import FontProperties
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)
In other blogs, the font.family part of the matplotlibrc file, which is the environment file of matplotlib, is specified by the DL font name, and the font to be used is rewritten, but the matplotrc file cannot be rewritten. It is solved by passing fontproperties = font_prop as an argument each time when plotting. (* It is a little annoying to write in the argument one by one, but if you do not display Japanese with matplotlib so often, change it temporarily rather than rewriting the environment file and getting confused. It may be easier)
As a point to note when passing fontproperties = font_prop one by one and displaying it in Japanese, The point that prop = font_prop instead of fontproperties = font_prop only when plt.legend.
plt.legend(['hoge'], prop=font_prop, loc='upper left') (Remarks) Delete the Font cache of Matplotlib If the font cache remains, it may not be reflected even if the setting is changed, so delete it
$ rm ~/.cache/matplotlib/fontList.cache
Recommended Posts