https://zhuanlan.zhihu.com/p/81262346
https://superuser.com/questions/1153990/anyone-know-how-to-install-arial-fonts-on-centos-7
http://jonathansoma.com/lede/data-studio/matplotlib/list-all-fonts-available-in-matplotlib-plus-samples/
Add Arial to jupyter envrionment
- Download and install
wget http://www.itzgeek.com/msttcore-fonts-2.0-3.noarch.rpm
sudo rpm -Uvh msttcore-fonts-2.0-3.noarch.rpm
sudo fc-cache -fv
#Check if installed
fc-list
Arial font is under /usr/share/fonts/msttcore/
- Clear Cache:
cd ~/.cache/matplotlib
rm -r *
- Go to corresponding font dir in jupyter env:
- find dir in jupyter
import matplotlib
matplotlib.matplotlib_fname()
/home/xbao/.conda/envs/py37/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
- copy font:
cp /usr/share/fonts/msttcore/arial* /home/xbao/.conda/envs/py37/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf`
- rebuild font lib in jupyter:
from matplotlib.font_manager import _rebuild
_rebuild()
- check all available fonts in jupyter:
import matplotlib.font_manager
from IPython.core.display import HTML
def make_html(fontname):
return "<p>{font}: <span style='font-family:{font}; font-size: 24px;'>{font}</p>".format(font=fontname)
code = "\n".join([make_html(font) for font in sorted(set([f.name for f in matplotlib.font_manager.fontManager.ttflist]))])
HTML("<div style='column-count: 2;'>{}</div>".format(code))
- set font:
from matplotlib import rcParams
print(rcParams['font.family'])
rcParams['font.sans-serif']=['Arial']
- test
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], label='test')
ax.legend()