matplotlib summary

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 ='./TakaoPGothic.ttf' Specify the #DL path. It does not have to be under / font

font_path = '/usr/share/fonts/ipa-pgothic/ipagp.ttf' font_prop = FontProperties(fname=font_path)

Example

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.

Example

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

matplotlib summary
pandas Matplotlib Summary by usage
Matplotlib memorandum
Python Summary
Django Summary
Matplotlib gallery
Matplotlib memo
Linux Summary
Python summary
Django Summary
pyenv summary
String summary 1
pytest summary
Grammar summary that is often forgotten with matplotlib
AtCoderBeginnerContest180 Review & Summary
Kaggle Summary: Outbrain # 2
LINQ library summary
Sphinx setup summary
AtCoderBeginnerContest181 Review & Summary
Translucent matplotlib legend
Digital technology summary
AtCoderBeginnerContest182 Review & Summary
Python tutorial summary
#Python basics (#matplotlib)
blockdiag grammar summary
AtCoderBeginnerContest183 Review & Summary
AtCoderBeginnerContest179 Review & Summary
Kaggle Summary: Outbrain # 1
update, upgrade summary
My matplotlib (python)
Japanese with matplotlib
Standard input summary
Django filter summary
matplotlib graph album
Animation with matplotlib
python related summary
Histogram with matplotlib
2020 IT Conference Summary
Visualize summary statistics
Animate with matplotlib
Try using matplotlib
pytest usage summary
Docker command summary
Python basics summary
Kaggle related summary