matplotlib font

2020-12-24  本文已影响0人  sgzzl

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

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/

cd ~/.cache/matplotlib
rm -r *
import matplotlib
matplotlib.matplotlib_fname()

/home/xbao/.conda/envs/py37/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc

cp /usr/share/fonts/msttcore/arial* /home/xbao/.conda/envs/py37/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf`
from matplotlib.font_manager import _rebuild
_rebuild()
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))
from matplotlib import rcParams
print(rcParams['font.family'])
rcParams['font.sans-serif']=['Arial']
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], label='test')

ax.legend()
上一篇 下一篇

猜你喜欢

热点阅读